Back to October Back to Year 2026
EASY 19 Oct 2026 View on LeetCode

2089. Find Target Indices After Sorting Array

</> Solution

/**
 * Problem: LeetCode 2089 - Find Target Indices After Sorting Array
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
import java.util.ArrayList;
import java.util.List;

/**
 * Problem: LeetCode 2089 - Find Target Indices After Sorting Array
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public List<Integer> targetIndices(int[] nums, int target) {
        int less = 0, equal = 0;
        for (int x : nums) {
            if (x < target) less++;
            else if (x == target) equal++;
        }
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < equal; i++) {
            result.add(less + i);
        }
        return result;
    }
}

TIME COMPLEXITY

O(N)

SPACE COMPLEXITY

O(1)

TOPICS

Array Binary Search Counting Frequency Counting Sorting