Find Target Indices After Sorting the Array

Easy

Topics
ArrayBinary SearchSorting

Given an array nums and an integer target, first sort nums in non-decreasing order. Return the list of indices i (in increasing order) such that after sorting nums[i] == target. If target is not present, return an empty list.

Example 1

Input:  nums = [1,2,5,2,3], target = 2
Output: [1,2]

Example 2

Input:  nums = [1,2,5,2,3], target = 3
Output: [3]

Example 3

Input:  nums = [1,2,5,2,3], target = 5
Output: [4]

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i], target <= 100
Run ⌘' · Submit ⌘⏎