FastPrepFirst and Last Position in a Sorted Array
Problems/First and Last Position in a Sorted Array

First and Last Position in a Sorted Array

Akuna Capital logoAkuna Capital● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports name the well-known first-and-last-position task. We chose the number limits and the examples.

Our version is about 98% the same as the reported questions.

You are given an integer array nums sorted in nondecreasing order and an integer target.

Return the zero-based indices of the first and last occurrence of target as [first, last]. If the target is absent, return [-1, -1].

Your solution must run in O(log n) time, where n = nums.length.

Function

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

Examples

Example 1

nums = [1,2,2,2,4,7]target = 2return = [1,3]

The target occurs at indices 1, 2, and 3, so the first index is 1 and the last is 3.

Example 2

nums = [1,2,2,2,4,7]target = 3return = [-1,-1]

The value 3 does not occur in the array.

Example 3

nums = []target = 0return = [-1,-1]

An empty array contains no target.

Constraints

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

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • First and Last Target Position in a Mountain ArrayGoogle · ONSITE INTERVIEWGoogle interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Koko Eating BananasThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Smallest Batch Size Within a Step LimitMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find First and Last Position in a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Peak of an Increasing-Then-Decreasing ArraySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Aggressive CowsAmazon · PHONE SCREEN

Interview reports that mention this question

  • Akuna Capital QR Screens and Coding: 77 Experiences (Part 1 of 6)

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public int[] searchRange(int[] nums, int target) {
        // write your code here
    }
}
Checking account…