FastPrepLast Position of a Target in a Sorted Array

Last Position of a Target in a Sorted Array

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

nums is sorted in nondecreasing order. Return the zero-based index of the final occurrence of target, or -1 if target is absent.

Function

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

Examples

Example 1

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

The final 2 occurs at index 3.

Constraints

  • 0 <= nums.length <= 10^5.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int lastPosition(int[] nums, int target) {
  // Write your code here.
}
nums[1,2,2,2,3]
target2
expected3
Checking account…