ORIGINAL CODING QUESTION
Latest matching release
Release build numbers are stored in nondecreasing order, and the same build number can appear several times when a release was re-deployed. Return the zero-based index of the LAST occurrence of the target build number, or -1 when the target never appears.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n sorted build numbers, then target. Print an index or -1.
Constraints
1 ≤ n ≤ 200; build numbers and target in [-1000, 1000]; the list is nondecreasing.
Example 1
Input
6 1 2 2 2 5 9 2
Output
3
Build 2 occupies indexes 1 to 3, so the answer is 3.
Example 2
Input
4 1 3 5 7 4
Output
-1
Build 4 is not present.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Find the first index whose value is strictly greater than the target.
Hint 2
Keep a half-open range [lo, hi); move lo past mid when a[mid] <= target, otherwise shrink hi to mid.
Hint 3
The candidate is lo - 1; confirm that it exists and holds the target before returning it.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →