← Bloomberg Interview Insights

Bloomberg·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Bloomberg coding round, pretty standard binary search territory but with a twist at the end that I didn't fully think through in time.

Questions Asked (2)

Q1

Given a sorted array of integers and a target value, return the indices of the first and last occurrence of the target. Return [-1, -1] if not found. Must run in O(log n).

Algorithms & Data Structures
Author's notes

Classic binary search variant.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search twice: once to find the leftmost occurrence and once to find the rightmost occurrence. For the leftmost, when the target is found, continue searching in the left half; for the rightmost, continue in the right half. This ensures O(log n) time and handles duplicates efficiently.

Pro tip: Clarify upfront that you'll use two binary searches to avoid confusion with a single modified search, and mention edge cases like empty array or target not present. This shows structured thinking and attention to detail.

1. Clarify requirements and edge cases

Confirm the array is sorted, may contain duplicates, and that O(log n) is required. Discuss edge cases: empty array, target smaller/larger than all elements, target not present.

2. Design leftmost binary search

Implement a binary search that finds the first occurrence: when nums[mid] == target, record mid and move the right pointer to mid-1 to search for an earlier occurrence.

3. Design rightmost binary search

Implement a similar binary search for the last occurrence: when nums[mid] == target, record mid and move the left pointer to mid+1 to search for a later occurrence.

4. Combine results and handle not found

If either search fails to find the target, return [-1, -1]. Otherwise, return the indices from the two searches.

5. Analyze complexity and test

State that time complexity is O(log n) and space is O(1). Walk through a small example to verify correctness.

Key Points to Mention

  • Binary search modification to find boundaries
  • Time complexity O(log n) and space O(1)
  • Handling duplicates by continuing search in the appropriate half
  • Edge cases: empty array, target not present, single element
  • Avoiding integer overflow in mid calculation (use low + (high - low) / 2)
  • Returning [-1, -1] when target is not found

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

Q2

Follow-up: if new numbers strictly larger than the current maximum keep getting appended to the array, how do you efficiently maintain the first and last occurrence of the target as the array grows?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the target's first and last occurrences are fixed once the target has appeared, because new elements are strictly larger than the current maximum and therefore cannot equal the target. Then explain that you only need to track the first and last indices when the target is first encountered, and that subsequent appends require no updates to these positions.

Pro tip: Mention that if the target is the current maximum, appending larger numbers means the target will never appear again, so its last occurrence is fixed at the time of the last append of the target. This shows you understand the monotonic property and can avoid unnecessary work.

1. Clarify the constraints

Confirm that new elements are strictly larger than the current maximum, so they cannot be equal to the target if the target is less than or equal to the current maximum. If the target is the current maximum, new elements are larger, so the target will not appear again.

2. Track first and last occurrence

Maintain variables for the first and last index of the target. When the target is first seen, set both. On subsequent occurrences, update only the last index.

3. Handle appends efficiently

When a new element is appended, check if it equals the target. If yes, update the last index. If no, and it's larger than the target, do nothing because the target cannot appear again.

4. Analyze complexity

Explain that each append is O(1) time, and the first and last occurrences are maintained in O(1) space. No additional data structures are needed.

5. Consider edge cases

Discuss cases where the target never appears, appears only once, or is the maximum element. Also consider if the target is larger than all elements initially, then it may appear later.

Key Points to Mention

  • Monotonic property: new elements are strictly larger than the current maximum, so the target's occurrences are bounded.
  • First occurrence is fixed once the target is first seen; last occurrence only changes if the target is appended again.
  • If the target is less than the current maximum, it cannot appear in future appends.
  • If the target equals the current maximum, it may appear in future appends only if the appended element equals the target, but since appends are strictly larger, it won't.
  • O(1) time per append and O(1) space to maintain first and last indices.
  • Edge cases: target never appears, target appears once, target is the maximum, target is larger than all initial elements.

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