← 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
Hiring now
Slice has 19 open roles right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Social Media Coordinator (Part-time)
Pristina, Kosovo
Senior Inside Sales Representative
Skopje, Pristina
Engineering Manager, Services
Remote
Next question