#2089
Find Target Indices After Sorting Array
newbie · 200 · lc easy +16 · verified · 77.8% accepted · 1,952 likes · top 89%
Description
Given a 0-indexed integer array nums and an integer target, sort nums in non-decreasing order and return all indices where nums[i] == target in increasing order. Return an empty list if no such index exists.
Example 1:
Input: nums = [1,2,5,2,3], target = 2
Output: [1,2]
Explanation: After sorting, nums is [1,2,2,3,5].
The indices where nums[i] == 2 are 1 and 2.
Example 2:
Input: nums = [1,2,5,2,3], target = 3
Output: [3]
Explanation: After sorting, nums is [1,2,2,3,5].
The index where nums[i] == 3 is 3.
Example 3:
Input: nums = [1,2,5,2,3], target = 5
Output: [4]
Explanation: After sorting, nums is [1,2,2,3,5].
The index where nums[i] == 5 is 4.
Code
1
2
3