LeetCode 34: Find First and Last Position of Element in Sorted Array

Problem Requirement Start with the official input nums = [5,7,7,8,8,10] and target = 8. The answer must be the complete range [3,4]; returning only index 3 or 4 does not identify both the target’s first and last occurrences. Given an integer array nums sorted in non-decreasing order and an integer target: If target exists, return the indices of its first and last occurrences as [first, last]. If target does not exist, return [-1, -1]. The problem ultimately requires an algorithm with O(log n) runtime. LeetCode uses this method contract: ...

March 18, 2026 · 15 min · map[name:Jeanphilo]