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

Paytm logoPaytm● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Paytm new grad onsite interview. A report names this well-known task. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

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.

Source note: Author-written prompt excerpt retained for source fidelity.

More Paytm interview questions

  • Detect a Linked-List CycleONSITE INTERVIEW · Seen Sep 2026
  • Minimum Coins for a TargetONSITE INTERVIEW · Seen Sep 2026
  • Nth Highest SalaryPHONE SCREEN · Seen Nov 2026
  • Second Highest SalaryPHONE SCREEN · Seen Nov 2026
  • Jump GamePHONE SCREEN · Seen Nov 2026
  • LRU Cache with Expiring EntriesPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • 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
  • Smallest Batch Size Within a Step LimitMicrosoft · ONSITE INTERVIEWMicrosoft 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
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Search in Rotated Sorted ArrayKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Detect a Silent SensorConfluent · ONSITE INTERVIEWConfluent interview questions
All Paytm interview questionsSee Paytm hiring insights
Saved
class Solution {
    public int[] searchRange(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…