LeetCode Entry

2089. Find Target Indices After Sorting Array

19.10.2026 easy 2026 kotlin rust

Positions of target in sorted order

2089. Find Target Indices After Sorting Array easy substack youtube

https://dmitrysamoylenko.com/leetcode/

19.10.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1516

Problem TLDR

Positions of target in sorted order

Intuition

Sort. Then filter positions. Or count elements less and equal to the target.

Approach

  • Rust has a nice positions filter

Complexity

  • Time complexity: \(O(n^2)\)

  • Space complexity: \(O(n)\)

Code

    fun targetIndices(n: IntArray, t: Int)=
    n.indices.filter{n.sorted()[it]==t}
    pub fn target_indices(n: Vec<i32>, t: i32) -> Vec<i32> {
        n.into_iter().sorted().positions(|x| x == t).map(|i| i as _).collect()
    }

Comments