Return all positions where the target appears after the array is sorted in non-decreasing order.
Problem
You are given an integer array nums and an integer target.
Imagine sorting nums in non-decreasing order. Your task is to return every index at which target appears in the sorted array.
The answer should list the indices in increasing order.
Goal
Compute the set of indices where target occurs after sorting, without modifying the intended meaning of the result.
Input Format
- An integer array
nums - An integer
target
Output Format
- Return an array of integers containing all indices
isuch thatsorted(nums)[i] == target
Constraints
1 <= nums.length <= 10000 <= nums[i] <= 10000 <= target <= 1000
Example 1
Input
nums = [1,2,5,2,3], target = 2
Output
[1,2]
Explanation
After sorting, the array becomes [1,2,2,3,5]. The target 2 appears at indices 1 and 2.
Example 2
Input
nums = [1,2,5,2,3], target = 3
Output
[3]
Explanation
After sorting, the array becomes [1,2,2,3,5]. The target 3 appears at index 3.
Show 1 more example
Example 3
Input
nums = [1,2,5,2,3], target = 5
Output
[4]
Explanation
After sorting, the array becomes [1,2,2,3,5]. The target 5 appears at index 4.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.