Skip to main content
Back to problems
Leetcode
Easy
Arrays
Sorting
Find Target Indices After Sorting Array

Return all positions where the target appears after the array is sorted in non-decreasing order.

Acceptance 0%
Problem Statement

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 i such that sorted(nums)[i] == target

Constraints

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] <= 1000
  • 0 <= target <= 1000
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.