You are given a 0-indexed integer array nums and a target element target.

A target index is an index i such that nums[i] == target.

Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.

&nbsp;
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.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 100
	1 &lt;= nums[i], target &lt;= 100


class Solution:
    def targetIndices(self, nums, target):
        ans = []
        for i,num in enumerate(sorted(nums)):
            if num == target: ans.append(i)
        return ans
class Solution {
    /** Algorithm:
        - Parse the array once and count how many are lesser than target and how many are equal
        - DO NOT sort the array as we don't need it sorted.
          Just to know how many are lesser and how many are equal. O(N) better than O(NlogN - sorting)
        - The response list will have a size = with the number of equal elements (as their positions)
        - Loop from smaller to smaller+equal and add the values into the list. Return the list
    */
    public List<Integer> targetIndices(int[] nums, int target) {
        int smaller = 0;
        int equal = 0;
        for (int num : nums) {
            if (num < target) {
                smaller++;
            } else if (num == target) {
                equal++;
            }
        }
        List<Integer> indices = new ArrayList<>(equal);
        for (int i = smaller; i < smaller + equal; i++) {
            indices.add(i);
        }
        return indices;
    }
}
class Solution {
public:
    vector<int> targetIndices(vector<int>& nums, int target) {
        vector<int> result;
        sort(nums.begin(),nums.end());
        for(int i=0;i<nums.size();i++){
            if(nums[i]==target) result.push_back(i);
        }
        return result;
    }
};
function binarySearch(lists, sorted, low, high, target){
    if(low > high) return;

    const mid = low + Math.floor((high - low) / 2);

    if(sorted[mid] === target){
    lists.push(mid);
    }

    binarySearch(lists, sorted, low, mid-1, target);
    binarySearch(lists, sorted, mid+1, high, target);
}

var targetIndices = function(nums, target) {
    let result = [];
    nums.sort((a,b)=>a-b);
    if(!nums.includes(target)) return [];

    binarySearch(result, nums, 0 , nums.length-1, target);
    return result.sort((a,b) => a-b);
}
Find Target Indices After Sorting Array