← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Junior

JuniorPrefer not to say
Apr 2026

Summary

Google SWE screen with a binary search problem. Pretty straightforward session, nothing tricky thrown in.

Questions Asked (1)

Q1

Given a sorted integer array and a target value, return the index of the target or -1 if it doesn't exist. Must run in O(log n) time.

Algorithms & Data Structures
Author's notes

Classic binary search, nothing fancy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that the sorted array and O(log n) requirement indicate binary search. Explain the algorithm step-by-step, emphasizing how you maintain the search space and update pointers. Then, discuss edge cases and complexity.

Pro tip: Mention that you'd use mid = left + (right - left) // 2 to avoid integer overflow, and clarify whether to return any occurrence or the first/last occurrence if duplicates exist.

1. Clarify the problem

Confirm assumptions: array is sorted ascending, may contain duplicates, and we need to return any index of the target or -1 if not found. Ask if the array can be empty or if there are constraints on values.

2. Choose binary search

Explain that binary search is optimal for sorted arrays with O(log n) time. Initialize left and right pointers to the start and end of the array.

3. Implement the search loop

While left <= right, compute mid, compare array[mid] with target. If equal, return mid; if array[mid] < target, move left to mid+1; else move right to mid-1.

4. Handle termination and edge cases

If the loop ends without finding the target, return -1. Discuss edge cases: empty array, single element, target smaller than first element, target larger than last element.

5. Analyze complexity and test

State time complexity O(log n) and space O(1). Walk through a small example to verify correctness, and mention potential pitfalls like integer overflow in mid calculation.

Key Points to Mention

  • Binary search requires a sorted array and divides the search space in half each iteration.
  • Use mid = left + (right - left) // 2 to prevent integer overflow in languages like Java/C++.
  • Time complexity is O(log n) because the search space halves each step; space complexity is O(1) for iterative approach.
  • Handle duplicates by specifying whether to return any index or the first/last occurrence; if not specified, returning any is acceptable.
  • Edge cases: empty array, target not present, target at boundaries, and arrays with one element.
  • Test with examples: e.g., array [1,3,5,7], target 5 returns 2; target 2 returns -1.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.