Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Check if Element Exists

Easy Acceptance 87% Points 20

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.

Constraints
  • 1 = arr.length = 105
  • -104 = arr[i], target = 104
Topics
Binary Search
Companies
Flipkart
Added 19 Jul 2026 87% acceptance
Ln 1, Col 1Sign in to save your code
1
1
true