← All questions
MediumCoding
Find First and Last Position of Element in Sorted Array
Asked at
Slice
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Use lower bound to find first index with value at least target.
- 02Verify it equals target.
- 03Use upper bound to find first index greater than target.
- 04Subtract one for the last occurrence.
- 05Return missing markers if target is absent.
Reference answer
Then expect these follow-ups
How does lower bound differ from a normal search?
Tests: follow-up reasoning
Can you write this with inclusive bounds safely?
Tests: follow-up reasoning
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question