CT924

The Range Finder: Locate the Search Range Efficiently

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the mapping department of Prime City, the Cartographer uses exponential search to find the range [L, R] in a sorted array where all occurrences of a target value reside. This combines exponential search to find the range, then binary search for the exact boundaries. "First use exponential search to find any occurrence of the target," the Cartographer says. "Then expand left and right to find the full range. Output the leftmost and rightmost indices." Given a sorted array of N integers and a target T, find the range [left, right] of all occurrences of T. If T is not found, output -1 -1. Constraints: 1 <= N <= 10^5, -10^9 <= array[i], T <= 10^9, sorted non-decreasing Input: 7 1 2 2 2 3 4 5 2 Output: 1 3 Input: 5 1 3 5 7 9 4 Output: -1 -1

Constraints:

1 <= N <= 10^5, sorted non-decreasing

Tags:

exponential-search range-search binary-search search
Loading...
Test Cases:No test cases
No test cases available.
The Range Finder: Locate the Search Range Efficiently - MEDIUM Coding Problem | CodeTikki