Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Find Target Indices After Sorting the Array

Easy

Topics
ArrayBinary SearchSorting

Given an array nums and an integer target, first sort nums in non-decreasing order. Return the list of indices i (in increasing order) such that after sorting nums[i] == target. If target is not present, return an empty list.

Example 1

Input:  nums = [1,2,5,2,3], target = 2
Output: [1,2]

Example 2

Input:  nums = [1,2,5,2,3], target = 3
Output: [3]

Example 3

Input:  nums = [1,2,5,2,3], target = 5
Output: [4]

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i], target <= 100
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access