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

Find First and Last Position of Element in Sorted Array

EPAM logoEPAM● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The named exercise gives the whole task. We chose the limits and the function signature. Our version is about 99% the same as the named exercise.

Given an integer array nums sorted in nondecreasing order and an integer target, return a two-element array containing the first and last indices at which target appears.

If target 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 through 4.

Example 2

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

The target is absent.

Constraints

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

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

More EPAM Phone Screen questions

  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Container With Most WaterPHONE SCREEN · Seen Oct 2026
  • Convert an Entry List to a MapPHONE SCREEN · Seen Oct 2026
  • Count Array Element FrequenciesPHONE SCREEN · Seen Oct 2026
  • Group AnagramsPHONE SCREEN · Seen Oct 2026
  • Longest Consecutive SequencePHONE SCREEN · Seen Oct 2026
  • Max Consecutive Ones IIIPHONE SCREEN · Seen Oct 2026
  • Minimum Currency ConversionsPHONE SCREEN · Seen Oct 2026
  • Next Greater Element IPHONE SCREEN · Seen Oct 2026
  • Partition and Group Values by ParityPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • 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
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
  • Search in Rotated Sorted ArrayZoomInfo · PHONE SCREEN
  • Find a Peak ElementFox Corporation · PHONE SCREEN
All EPAM interview questionsSee EPAM hiring insights
Saved
class Solution {
    public int[] searchRange(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…