Solved LeetCode Problem 448 with Cyclic Sort

Problem 24 : LeetCode 🚀 LeetCod Solved — Problem #448: Find All Numbers Disappeared in an Array (Cyclic Sort Approach) 🧩 Today, I explored another elegant application of the Cyclic Sort algorithm — solving the classic “Find All Numbers Disappeared in an Array” problem from LeetCode. 🔍 Problem Overview Given an array of integers where 1 ≤ a[i] ≤ n (with n being the array size), some elements appear twice while others appear once. The task: Find all numbers that do not appear in the array, with ⏱️ O(n) runtime 🧠 O(1) extra space 💡 My Approach — Cyclic Sort in Action I used Cyclic Sort for an in-place, efficient solution: In-Place Placement: Each number x should ideally be placed at index x - 1. During iteration, if arr[i] isn’t in its correct position and its target spot isn’t already occupied, I swap the two elements. Missing Number Detection: After sorting, I perform a linear scan — for every index i where arr[i] != i + 1, the missing number is i + 1. ⚙️ Results ✅ Time Complexity: O(n) — Runtime 7 ms, beating 47.63% of Java submissions ✅ Space Complexity: O(1) — Achieved true in-place solution (no extra data structures) ✅ Memory: 67.09 MB — beating 5.95% of submissions 🧩 Tech Stack: Java | Cyclic Sort | Array Manipulation | In-Place Algorithms | DSA Every such problem reinforces my understanding of data placement logic, index manipulation, and memory efficiency — skills essential for writing optimized backend and system-level code. #LeetCode #Java #ProblemSolving #DataStructures #Algorithms #CyclicSort #InPlaceAlgorithm #BackendDevelopment #SpringBoot #DSA #LearningInPublic #CodingJourney  Link : https://lnkd.in/d4Z8zTE4

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories