Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check if Element Exists

Easy Acceptance 87.00% Points 20.00

Given an array of integers and a target value, determine whether the target element exists in the array. Return true if the element is present, otherwise return false.

Examples
Example 1

Example 1

Input: arr = [1,3,5,7,9], target = 5

Output: true

Explanation: The element 5 is present in the array, so the result is true.

Example 2

Example 2

Input: arr = [2,4,6,8], target = 3

Output: false

Explanation: The element 3 does not exist in the array, so the result is false.

Example 3

Example 3

Input: arr = [], target = 1

Output: false

Explanation: The array is empty, so no element exists.

Hints
Hint 1
N/A
Constraints
  • 1 = arr.length = 105
  • -104 = arr[i], target = 104
Companies
Flipkart
Topics
Binary Search
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions