Find Target Indices After Sorting Array

Easy
11
73.6% Acceptance

In this lab, you will be working with a 0-indexed integer array nums and a target element target. Your task is to find the target indices of nums after sorting the array in non-decreasing order. A target index is an index i such that nums[i] == target. You need to return a list of the target indices, sorted in increasing order. If there are no target indices, return an empty list.

For example:

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. 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. 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.

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i], target <= 100

Keep the following points in mind while building the lab:

  • Use ESM import/export everywhere.
  • Check for all edge cases while building the lab and implement correct and precise evaluation scripts.
  • Be very careful with the order of challenges written and their respective testing blocks in the evaluation script.
  • You may use Puppeteer for running user's code, for example.

Once you have built the lab files, make sure to test the lab thoroughly using the evaluation scripts, checking for edge cases and correctness. And finally, submit your properly formatted lab in markdown and the respective lab files. Good luck!