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
Solved LeetCode Problem 448 with Cyclic Sort
More Relevant Posts
-
Problem 26 : LeetCode 🚀 LeetCode Medium Solved: Find All Duplicates in an Array (Cyclic Sort Approach) 🧩 I just tackled another LeetCode Medium challenge — this one tested both my problem-solving and in-place algorithm design skills. 🔍 Problem Overview: Given an array of integers where each value is between 1 and n, the goal was to find all duplicate numbers — with O(n) time and O(1) extra space. 💡 My Approach – Cyclic Sort Logic: I used the Cyclic Sort algorithm, which treats the array itself like a hash map. Each element x should be at index x - 1. During the sorting process: If the element is not in the right place → swap it. If a duplicate is detected (arr[i] == arr[arr[i]-1]) → record it. This approach avoids using any extra data structure for indexing and works entirely in-place. ⚙️ Results: ✅ Runtime: 14 ms → Beats 42.80% of Java submissions ✅ Memory: 59.84 MB → Beats 8.98% of submissions ✅ Complexity: O(n) time | O(1) space ✅ Status: Accepted 🎉 (All 29 test cases passed) 📚 Tech Stack Used: Java | Cyclic Sort | HashSet | Array Manipulation | DSA Every solved problem strengthens logic, debugging, and clarity of thinking — a step closer to writing efficient production-grade code. #LeetCode #Java #ProblemSolving #CyclicSort #DataStructures #Algorithms #BackendDeveloper #SpringBoot #LearningInPublic #CodeJourney Question Url : https://lnkd.in/dwz6UWyH
To view or add a comment, sign in
-
-
Problem 27 : LeetCode 🎯 LeetCode Problem #645 Solved — Set Mismatch (Cyclic Sort Approach) 🧩 Today, I solved another interesting LeetCode Easy problem — “Set Mismatch”, which deepened my understanding of in-place sorting and index mapping using the Cyclic Sort technique. 🔍 Problem Overview Given an integer array nums where numbers are supposed to be from 1 to n, one number is duplicated, and one number is missing. The task: Find both numbers using O(n) time and O(1) space. 💡 My Approach — Cyclic Sort Technique I treated the array like a self-mapping structure where each number x should ideally be placed at index x - 1. If the current element isn’t in its correct place and its target isn’t already filled, I swap it. After the array is sorted in place, any index i where arr[i] != i + 1 indicates: arr[i] → the duplicate number i + 1 → the missing number ⚙️ Results ✅ Runtime: 3 ms — Beats 79.76% of Java submissions ✅ Memory: 47.45 MB — Beats 6.28% of submissions ✅ Complexity: O(n) time | O(1) space ✅ Status: Accepted ✅ (All 49 test cases passed) 🧩 Tech Stack Java | Cyclic Sort | Array Manipulation | In-Place Algorithm | DSA Another problem that reinforces my confidence in index-based logic and memory-efficient coding patterns — vital skills for backend and system optimization. #LeetCode #Java #ProblemSolving #CyclicSort #DataStructures #Algorithms #InPlaceAlgorithm #BackendDevelopment #SpringBoot #DSA #LearningInPublic #CodingJourney Question Url : https://lnkd.in/dixwjFE3
To view or add a comment, sign in
-
-
🚀 Day 52 of #100DaysOfCode 🚀 Today I solved LeetCode Problem #389 – Find the Difference 🧩 This problem is a great example of using ASCII value manipulation to solve what seems like a string comparison challenge. 💡 Key Learnings: Strengthened understanding of character encoding (ASCII values) and how they can simplify logic. Learned how summing character values can help detect differences efficiently without extra data structures. Reinforced the value of O(n) solutions for string-based problems. 💻 Language: Java ⚡ Runtime: 1 ms — Beats 99.32% 🚀 📉 Memory: 41.9 MB — Beats 65.84% 🧠 Approach: 1️⃣ Convert both strings to character arrays. 2️⃣ Compute the sum of ASCII values of both. 3️⃣ The difference between sums gives the ASCII value of the extra character in t. Simple, elegant, and efficient! ⚙️ Sometimes, a clever use of ASCII arithmetic can replace complex logic — efficiency lies in simplicity. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingChallenge #Algorithms #DataStructures #SoftwareDevelopment #LearningEveryday #CleanCode
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #852 – Peak Index in a Mountain Array 🏔️ 📘 Problem Statement: Given an integer array that first increases and then decreases (a “mountain array”), find the index of the peak element — the point where the sequence changes from increasing to decreasing. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% ⚡ 📉 Memory: 56.29 MB — Beats 60.76% 🧠 Concept Used: 🔹 Binary Search Optimization – Instead of linearly scanning the array, I applied binary search to achieve O(log n) time complexity. 🔹 This approach identifies the peak by checking midpoints and adjusting the search range efficiently. 🧩 Approach: 1️⃣ Initialize low = 0 and high = arr.length - 1. 2️⃣ Use binary search: ➡️ If arr[mid] < arr[mid + 1], the peak lies to the right → move low = mid + 1. ➡️ Else, the peak is at mid or to the left → move high = mid. 3️⃣ Return low when low == high — the index of the peak. ✅ Complexity: Time: O(log n) Space: O(1) ✨ Takeaway: Binary Search isn’t just for finding numbers — it’s a pattern for optimizing any “search in sorted behavior” scenario. Learning to spot monotonic trends in problems can turn O(n) solutions into O(log n) ones! #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #BinarySearch #DataStructures #CodingChallenge #CleanCode #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 146 / 180 of #180DaysOfCode ✅ Today’s Highlight: Revisited LeetCode 3234 — “Count the Number of Substrings With Dominant Ones.” 🧩 Problem Summary: Given a binary string s, the task is to count how many of its substrings have dominant ones. A substring is considered dominant if: number of 1s ≥ (number of 0s)² This creates an interesting balance check between zeros and ones, pushing you to think about substring ranges, prefix behavior, and efficient counting techniques. 💡 Core Takeaways: Great exercise in string analysis and prefix-based reasoning Highlights how mathematical conditions influence algorithm design Reinforces handling frequency relationships inside a sliding or expanding window Efficient counting becomes essential due to potential O(n²) substrings 💻 Tech Stack: Java ⏱ Runtime: 115 ms (Beats 84.11%) 💾 Memory: 47 MB 🧠 Learnings: Strengthened understanding of substring behavior under unique constraints Refined thinking around optimizing brute-force patterns A good reminder of how theoretical conditions (like squaring zeros) change practical implementation choices 📈 Progress: Today’s problem significantly improved my intuition around constraint-based substring evaluation—valuable for more advanced algorithmic challenges ahead. #LeetCode #Java #Algorithms #SubstringProblems #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #180DaysOfCode #LogicBuilding #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day-75 of #100DaysCodeOfChallenge 💡 LeetCode Problem: 1526. Minimum Number of Increments on Subarrays to Form a Target Array (Hard) 🧠 Concepts Practiced: Greedy Algorithms | Array Manipulation | Difference Computation Today’s challenge was a Hard-level problem, focusing on finding the minimum number of operations required to transform an initial array of zeros into a given target array — using only subarray increments. The key insight here was realizing that each increase in value from one element to the next represents a required new operation on LeetCode. Instead of simulating every subarray operation, we can simply sum up the positive differences between consecutive elements — a great example of mathematical optimization through observation 💭 🔹 Intuition: Only when a number increases compared to the previous one, a new increment operation is needed. ⚙️ Language: Java ⚡ Runtime: 3 ms (Beats 100%) 💾 Memory: 56.82 MB (Beats 61.41%) ✅ Result: 129 / 129 test cases passed — Accepted! 🎯 Each “hard” problem solved adds one more layer of confidence — and reminds me that persistence pays off 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #CodingChallenge #GreedyAlgorithm #LearningJourney #TechMindset #KeepCoding #SoftwareEngineering #DeveloperLife #LogicBuilding
To view or add a comment, sign in
-
-
✨ Two Paths, One Goal: From Patterns to Problems (Day 48) ✨ Today, in collaboration with Chitrang Potdar, we begin a brand-new chapter in our DSA journey — Stacks. After exploring the flexibility of Linked Lists, we now move into a structure that defines order, control, and execution flow — the Stack. 💡 What is a Stack? A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. The element inserted last is the first one to be removed — just like a stack of plates or books. 🧩 Terminologies: Push → Insert an element onto the top of the stack. Pop → Remove the topmost element. Peek / Top → View the top element without removing it. isEmpty() → Check if the stack is empty. 🏗 Structure of a Stack: Top → [ 30 | 20 | 10 ] → Bottom (New elements are always added and removed from the top.) ⚙️ Importance of Stacks: Simplifies management of nested and sequential tasks. Provides controlled access — only one end is accessible. Backbone of recursion, parsing, and expression evaluation. 🌍 Real-Life Applications: 1️⃣ Undo/Redo operations in editors 2️⃣ Function call management (Recursion Stack) 3️⃣ Backtracking algorithms (Maze, Sudoku) 4️⃣ Expression evaluation and syntax parsing 5️⃣ Browser navigation (Forward/Backward) 🧠 Implementation in Java: We implemented Stacks using: Arrays → Fixed-size, index-based implementation. Linked Lists → Dynamic memory allocation, no fixed limit. 📌 Concepts Covered: Stack fundamentals and LIFO principle Core stack operations (push, pop, peek) Array-based and Linked List-based implementations Real-world significance and use cases 🚀 From tomorrow, we’ll begin working on Stack operations and applications — exploring how logic control and recursion work under the hood. 👉 Swipe for Java code examples. 👉 Don’t miss the Python edition by Chitrang Potdar. #Java #DSA #Stack #TwoPathsOneGoal #PatternToProblem #CodingJourney #LearningByDoing
To view or add a comment, sign in
-
-
🚩 Problem: 78. Subsets 🔥 Day 56 of #100DaysOfLeetCode 🔍 Problem Summary: Given an integer array nums, return all possible subsets (the power set). The solution set must not contain duplicates, and the order does not matter. 🧠 Intuition: This is one of the simplest and cleanest backtracking problems. At each index, you have only two choices: Include the current element Exclude the current element This naturally builds the entire power set. Alternatively, you can also build subsets by expanding a list from left to right. ✅ Backtracking Approach: Start with an empty subset Recursively explore adding each number After each choice, backtrack and remove it Add all generated combinations into the result Super clean and beginner-friendly. ⚙️ Performance: ⏱️ Runtime: 1 ms 🚀 💪 Beats: 97% of Java solutions 💾 Memory: 43 MB ⚡ (Beats ~90% of users) 📊 Complexity: Time Complexity: O(n × 2ᶰ) Space Complexity: O(n) (recursion + temp list) ✨ Key Takeaway: This problem teaches the classic recursive structure used for: Subsets Combinations Nested choices Decision-tree exploration It's the perfect stepping stone to more advanced backtracking problems. Link:[https://lnkd.in/gfQV_8w4] #100DaysOfLeetCode #Day56 #Problem78 #Subsets #Backtracking #Recursion #Algorithms #DSA #Java #ProblemSolving #LeetCode #CodingChallenge #CodingCommunity #InterviewPreparation #CrackingTheCodingInterview #SoftwareEngineering #DataStructures #ArjunInfoSolution #DeveloperJourney #LearnToCode #TechCareers #CareerGrowth #CodeNewbie #ZeroToHero #CodingIsFun #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development