Find Target Indices After Sorting Array

Try to solve the Find Target Indices After Sorting Array problem.

Statement

You are given a 0-indexed array of positive integers, nums, and a value, target. The target represents an index ii in the array such that nums[i] == target.

Your task is to return a list of indexes of nums where the value equals target after sorting the array in nondecreasing order. If no such indexes exist, return an empty list. Ensure the returned list is sorted in increasing order.

Constraints:

  • 11 \leq nums.length 100\leq 100

  • 11 \leq nums[i], target 100\leq 100

Examples

Press + to interact
canvasAnimation-image
1 of 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Find Target Indices After Sorting Array

1

What is the output for the input nums = [1, 2, 3, 4] and target = 4?

A)

[0,1,2,3][0, 1, 2, 3]

B)

[3][3]

C)

[1,3][1, 3]

D)

[2][2]

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Drag and drop the cards to rearrange them in the correct sequence.

Try it yourself

Implement your solution in the following coding playground.

Press + to interact
Java
usercode > Solution.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Solution {
public static List<Integer> targetIndices(int[] nums, int target) {
// Replace the following placeholder return statement with your code
return new ArrayList<>();
}
}
Find Target Indices After Sorting Array

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.