LeetCode 2089: Target Indices After Sorting Array

Day 19 of Daily DSA 🚀 Solved LeetCode 2089: Find Target Indices After Sorting Array ✅ Approach: Instead of actually sorting the array, I counted: elements less than the target elements equal to the target The starting index is determined by how many elements are smaller than the target, and then indices are built for all equal elements. Simple counting → no extra sorting needed 💡 ⏱ Complexity: • Time: O(n) — single pass • Space: O(1) — excluding output list 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.83 MB (Beats 83.41%) A neat example of how thinking beyond “just sort it” can lead to cleaner and faster solutions. #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency #Arrays

  • graphical user interface, text

I did by sorting + bs, I didn't get this approach tbh . Thanks a lot man!! Actually if i have x elements smaller than target then starts at x after sorting....and if I have y elements equal to target then target ends at x+y-1

To view or add a comment, sign in

Explore content categories