Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Check If Element Exists

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Check If Element Exists. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Khan Academy may inspect an unsorted array of lesson identifiers while processing a learner's activity. Given an integer array and a target integer k, determine whether k appears in the array.

Return True if the target is present and False otherwise. Because the array is unsorted, do not assume that binary search can be used.

Formal Specification

Implement contains_value(values, k).

  • Input: values, a list of integers, and k, an integer target.
  • Output: A boolean indicating whether at least one element of values equals k.
  • Duplicate values do not change the result.
  • The input list must not be modified.

Constraints

  • 0 <= len(values) <= 10^5
  • -10^9 <= values[i] <= 10^9
  • -10^9 <= k <= 10^9
  • The array is not guaranteed to be sorted

Function Signature

def contains_value(values, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output