Mozilla | Onsite | Staff Full Stack Engineer

Anonymous User
104
Jun 07, 2024
Jun 07, 2024

The question was as follows:

inputs:

  1. a zip code
  2. A list of non-overlapping zip code ranges. These ranges are in sorted order.

Output:
Return a list of new ranges that includes the new zip code

Example 1:

Inputs:

  1. 12345
  2. [(12340, 12355), (12400, 12450)]

Output:
[(12340, 12355), (12400, 12450)]
12345 falls within an existing range, do nothing

Example 2:
inputs:
1.12346
2. [(12347, 12355), (12400, 12450)]

Output:
[(12346, 12355), (12400, 12450)]

12346 falls outside the existing range, but we can modify an existing range

Example 3:

This example, i am not sure of. I might have missed some claifying questions about which ranges should be merged.

inputs:
1.11235
2. [(11230, 11234), (11236, 11238)]

Output:
[(11230, 11238)]

I failed to come up with any working solution. My intiution was to use binary search to find an existing interval, but i got stuck after that.

Comments (4)