FastPrepFind First and Last Position in Sorted Array
Problems/Find First and Last Position in Sorted Array

Find First and Last Position in Sorted Array

Tennr logoTennr● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Tennr Implementation Engineer interview report directly links the well-known problem of finding the first and last position in a sorted array. Our version keeps the same task. Only the formatting and the stated log-time cost were cleaned up.

You are given an integer array nums sorted in non-decreasing order and an integer target.

Return [first, last], the first and last index where target occurs. If it is absent, return [-1, -1].

Your algorithm must run in O(log n) time.

Function

searchRange(nums: int[], target: int) → int[]

Examples

Example 1

nums = [5,7,7,8,8,10]target = 8return = [3,4]

The target occupies indices 3 and 4.

Example 2

nums = [5,7,7,8,8,10]target = 6return = [-1,-1]

The target is absent.

Constraints

  • 0 <= nums.length <= 100000.
  • -10^9 <= nums[i], target <= 10^9.
  • nums is sorted in non-decreasing order.

More Tennr Phone Screen questions

  • Top K Frequent ElementsPHONE SCREEN · Seen Aug 2025
  • Wildcard Multi-Delimiter ValidationPHONE SCREEN · Seen Aug 2025

Similar questions at other companies

  • Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
  • Koko Eating BananasThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Find First and Last Position in a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Aggressive CowsAmazon · PHONE SCREEN
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Find First and Last Position of Element in Sorted ArrayEPAM · PHONE SCREENEPAM interview questions
  • Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
  • Search in Rotated Sorted ArrayZoomInfo · PHONE SCREEN
See Tennr hiring insights
Saved
class Solution {
    public int[] searchRange(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…