Day 23/30 – Linked List Cycle II Solved a classic Linked List problem today. Goal: Detect the node where a cycle begins. Approach: • Use Floyd’s Cycle Detection Algorithm • Move slow (1 step) and fast (2 steps) pointers • When they meet, reset slow to head • Move both one step at a time to find the cycle start Time Complexity: O(n) Space Complexity: O(1) Efficient solution without extra memory. #30DaysOfDSA #Java #LinkedList #Algorithms #CodingChallenge
Detecting Cycle in Linked List with Floyd's Algorithm
More Relevant Posts
-
Day 83/100 – LeetCode Challenge ✅ Problem: #46 Permutations Difficulty: Medium Language: Java Approach: Backtracking with Swapping Time Complexity: O(n × n!) Space Complexity: O(n) for recursion stack Key Insight: Generate all permutations by fixing each element at current position and recursively permuting remaining elements. Use swapping to avoid extra space for visited tracking. Solution Brief: Base case: When index i reaches end, add current array as permutation. Recursive case: For each position j from i to end: Swap elements at i and j Recurse on i + 1 Swap back (backtrack) to restore original order #LeetCode #Day83 #100DaysOfCode #Backtracking #Java #Algorithm #CodingChallenge #ProblemSolving #Permutations #MediumProblem #Recursion #Swapping #DSA
To view or add a comment, sign in
-
-
Solved a matrix problem : checking whether one matrix can be obtained from another using rotations. At first it looked a bit tricky, but the key idea was simple: 👉 A 90° rotation can be done using transpose + reverse each row This makes the solution clean and efficient (O(n²)) and is a useful pattern to remember for similar problems. #DataStructures #Algorithms #DSA #Java #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 16/100 – LeetCode Challenge Problem: Merge Sorted Array Today’s problem involved merging two sorted arrays into one sorted array. Approach: Created a temporary array of size m + n Used two pointers to compare elements from both arrays Inserted the smaller element into the new array Copied remaining elements if any array still had values Finally copied the merged result back into nums1 Complexity: Time: O(m + n) Space: O(m + n) Concepts Practiced: Two-pointer technique Array traversal Merging sorted arrays #100DaysOfCode #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 49 of #100DaysOfCode Solved 86. Partition List on LeetCode 🔗 🧠 Key Insight: We need to rearrange a linked list such that: 🔹All nodes < x come before nodes ≥ x 🔹While maintaining the original relative order This is a classic linked list partitioning problem. ⚙️ Approach: 1️⃣ Create two dummy lists: 🔹small → nodes with values < x 🔹large → nodes with values ≥ x 2️⃣ Traverse the original list: 🔹Append each node to the appropriate list 3️⃣ Connect both lists: 🔹small → large 4️⃣ Return the head of the new list 🎯 This ensures: 🔹Stable ordering 🔹Clean and efficient separation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (no extra nodes, just pointers) #100DaysOfCode #LeetCode #DSA #LinkedList #Algorithms #Java #CodingPractice #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 52 of DSA – Construct Product Matrix Solved a matrix problem where each cell stores the product of all other elements except itself, modulo 12345. 💡 Key Insight: Use prefix and suffix products to get the result for each position without division. ⚡ Approach: Compute product of elements before each index Compute product of elements after each index Multiply both to form the answer ⏱️ Time Complexity: O(n × m) 💾 Space Complexity: O(n × m) #DSA #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 87/100 – LeetCode Challenge ✅ Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Direct Matrix Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) for result matrix Key Insight: Transpose swaps rows and columns: transposed[i][j] = matrix[j][i]. New matrix dimensions: col × row (original dimensions swapped). Solution Brief: Created result matrix with dimensions col × row. Nested loops assign each element to swapped position. Returned transposed matrix. #LeetCode #Day87 #100DaysOfCode #Matrix #Java #Algorithm #CodingChallenge #ProblemSolving #TransposeMatrix #EasyProblem #Array #2DArray #DSA
To view or add a comment, sign in
-
-
🧠 Day 32 / 100 – DSA Practice Solved Symmetric Tree on LeetCode 🌳✅ 🔹 Problem: Check whether a binary tree is a mirror of itself (symmetric around its center). 🔹 Approach: Used a recursive mirror check: Compare left subtree with right subtree Check if: ✔️ Values are equal ✔️ Left of one == Right of other ✔️ Right of one == Left of other 🔁 Recursively verified symmetry at each level 🔹 Complexity: ⏱ Time → O(n) 📦 Space → O(n) (recursion stack) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Understanding recursion patterns in trees is getting stronger day by day 🚀 #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinaryTree #Recursion #CodingJourney
To view or add a comment, sign in
-
-
Day 41 of Daily DSA 🚀 Solved LeetCode 20: Valid Parentheses ✅ Problem: Given a string containing only (), {}, [], determine if the input string is valid. Rules: Open brackets must be closed by the same type Open brackets must be closed in the correct order Every closing bracket must have a matching opening bracket Approach: Used a Stack to track opening brackets and validate matching pairs. Steps: Traverse the string Push opening brackets onto the stack For closing brackets → check top of stack If it matches → pop Else → return false At the end, stack should be empty ⏱ Complexity: • Time: O(n) • Space: O(n) 📊 LeetCode Stats: • Runtime: 3 ms (Beats 87.41%) ⚡ • Memory: 43.37 MB A classic stack problem that builds strong fundamentals for expression parsing & validation. #DSA #LeetCode #Java #Stack #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 100/100 – LeetCode Challenge ✅ Problem: #41 First Missing Positive Difficulty: Hard Language: Java Approach: In-Place Index Marking Time Complexity: O(n) Space Complexity: O(1) Key Insight: Place each positive integer in its correct position (index i should contain i+1). Mark presence using negative values without extra space. Solution Brief: First pass: replace numbers outside range [1, n] with n+1 (ignore them) Second pass: treat each number as index, mark that index negative Third pass: first positive index = missing number If all marked, answer is n+1 #LeetCode #Day100 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #FirstMissingPositive #HardProblem #InPlace #Optimization #DSA
To view or add a comment, sign in
-
-
🚀 Day 50 / 100 | Median of Two Sorted Arrays Intuition: We are given two sorted arrays and need to find the median of the combined numbers. Since both arrays are already sorted, we can merge them in sorted order. Once we have the merged array, finding the median becomes simple. If the total number of elements is odd, the median is the middle element. If it's even, the median is the average of the two middle elements. Approach: Use two pointers to traverse both arrays. Compare the elements and insert the smaller one into a new array. Continue this process until all elements are merged. Finally, calculate the median based on the length of the merged array. Complexity: Time Complexity: O(n + m) Space Complexity: O(n + m) #100DaysOfCode #Java #DSA #LeetCode #ProblemSolving
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