Find Target Indices After Sorting Array
Try to solve the Find Target Indices After Sorting Array problem.
We'll cover the following
Statement
You are given a 0-indexed array of positive integers, nums
, and a value, target
. The target
represents an index 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:
nums.length
nums[i]
,target
Examples
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
What is the output for the input nums = [1, 2, 3, 4]
and target = 4
?
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.
Try it yourself
Implement your solution in the following coding playground.
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 codereturn new ArrayList<>();}}
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.