FastPrepImplement Binary Search From Scratch
Problems/Implement Binary Search From Scratch

Implement Binary Search From Scratch

Cerebras logoCerebras● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported Cerebras technical screen asks for iterative binary search from scratch, correct not-found behavior, and complexity analysis; the judged task matches that prompt exactly.

Given an integer array sorted in nondecreasing order and a target, implement iterative binary search from scratch. Return the index of any occurrence of the target, or -1 when it is absent.

Function

binarySearch(nums: int[], target: int) → int

Examples

Example 1

nums = [-4,-1,0,3,9]target = 3return = 3

The target is at index 3.

Example 2

nums = [1,4,7,11]target = 5return = -1

The target does not occur.

Constraints

  • 0 <= nums.length <= 100000
  • -10^9 <= nums[i], target <= 10^9
  • nums is sorted in nondecreasing order.

More Cerebras problems

  • Dense Vector Dot ProductONSITE INTERVIEW · Seen Aug 2026
See Cerebras hiring insights
Saved
class Solution {
    public int binarySearch(int[] nums, int target) {
      // Write your iterative binary search here.
    }

}
Checking account…