Day 94 of my #100DaysOfCode Challenge Today’s problems focused on controlled rearrangement and sequential generation — reordering elements without losing structure, and producing patterns using level-wise expansion. Queues once again proved they’re not just about storage — they’re about flow. 🔹 1️⃣ Interleave the First Half of the Queue with Second Half — GFG The task was to rearrange a queue by interleaving its first half with the second half while preserving order. Key ideas: • Split the queue into two equal halves • Use an auxiliary queue for the first half • Alternately push elements from both halves • Maintain relative ordering throughout This problem shows how queues can be reshaped without random access — purely through controlled movement. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 🔹 2️⃣ Generate Binary Numbers — GFG Here, the challenge was to generate binary representations from 1 to n in order. Core strategy: • Use a queue to simulate BFS • Start with "1" • Generate next binaries by appending 0 and 1 • Process level by level A great example of how queues naturally model sequence generation and breadth-first expansion. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) Some problems rearrange what already exists. Others generate structure step by step. But both reinforce the same lesson: “When flow is controlled, complexity becomes predictable.” #100DaysOfCode #Day94 #Queue #BFS #GFG #Java #DSA #ProblemSolving #LearningInPublic 🚀
100 Days of Code: Queue Problems and Controlled Flow
More Relevant Posts
-
Day 96 of my #100DaysOfCode Challenge Today’s problem focused on real-time decision making and stream processing — determining what remains unique as data continuously arrives. Queues once again proved they’re not just about order — they’re about persistence. 🔹 1️⃣ Stream First Non-Repeating Character — GFG The task was to find the first non-repeating character at every step of a character stream. Key ideas: - Use a frequency array to track occurrences - Maintain a queue to preserve arrival order - Remove elements from the front once they repeat - The queue’s front always represents the current answer This problem beautifully demonstrates how queues help preserve historical context while handling streaming data efficiently. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) Some problems work on static input. Others demand answers as data flows in. But both reinforce the same lesson: “In streams, correctness depends on remembering just enough.” #100DaysOfCode #Day96 #Queue #StreamingData #GFG #Java #DSA #ProblemSolving #LearningInPublic 🚀
To view or add a comment, sign in
-
Day 95/100 – LeetCode Challenge ✅ Problem: #71 Simplify Path Difficulty: Medium Language: Java Approach: Stack-based Directory Parsing Time Complexity: O(n) Space Complexity: O(n) Key Insight: Split path by / and process each component: .. → pop from stack (go up one directory) . or empty → ignore (current directory) Valid directory name → push to stack Solution Brief: Used ArrayDeque as stack for directory components. Iterated through path components after splitting by /. Applied rules: .. → remove last directory if stack not empty . or empty → skip else → push to stack Built canonical path by joining stack components with /. Return "/" if empty, else constructed path. #LeetCode #Day95 #100DaysOfCode #Stack #String #Java #Algorithm #CodingChallenge #ProblemSolving #SimplifyPath #MediumProblem #Deque #PathParsing #DSA
To view or add a comment, sign in
-
-
Day 26 of Daily DSA 🚀 Solved LeetCode 225: Implement Stack using Queues ✅ Problem: Implement a LIFO stack using only queue operations. Approach: Used two queues: main queue → stores elements in stack order helper queue → assists during push operation Key idea: Move all elements from main to helper Insert the new element into main Move all elements back from helper to main This ensures the latest pushed element stays at the front, allowing pop() and top() in constant time. ⏱ Complexity: • push() → O(n) • pop() → O(1) • top() → O(1) • empty() → O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 42.54 MB (Beats 89.59%) A great problem to understand how one data structure can simulate another. #DSA #LeetCode #Java #DataStructures #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 98/160 – GFG Challenge 📌 Problem: Find Median in a Stream Today’s problem was all about handling real-time data efficiently. Instead of sorting every time (which is costly), we used a smart approach with two heaps. 🧠 Key Idea: Use a Max Heap (left side) → stores smaller half Use a Min Heap (right side) → stores larger half ⚖️ Balancing Rule: Size difference should not exceed 1 Always maintain order: max(left) ≤ min(right) 📊 Median Logic: If sizes unequal → median = top of max heap If equal → median = average of both tops 💡 What I Learned: How heaps help in stream processing problems Importance of balancing data structures dynamically Writing clean logic for real-time median calculation 🧪 Example: Input: [5, 15, 1, 3, 2, 8] Output: [5.0, 10.0, 5.0, 4.0, 3.0, 4.0] 🔥 Day 98 done! Getting stronger with DSA every day. #GFG160 #Day98 #DSA #Java #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 58/100 🚀 | #100DaysOfDSA Solved LeetCode 18 - 4Sum today. The task was to find all unique quadruplets in an array that sum up to a given target. The challenge here wasn’t just finding combinations — it was handling duplicates efficiently while keeping the solution optimal. Approach: Used sorting + two pointers to reduce complexity. • Sorted the array first • Fixed two indices (i and j) using nested loops • Used two pointers (left and right) to find remaining two elements • Skipped duplicates at every step to ensure unique quadruplets • Used long for sum to avoid integer overflow This approach reduces unnecessary checks and ensures all valid combinations are captured. Time Complexity: O(n³) Space Complexity: O(1) (excluding result storage) Key takeaway: Extending patterns like 2Sum → 3Sum → 4Sum helps in solving more complex problems efficiently. Handling duplicates correctly is just as important as finding the solution. #100DaysOfDSA #LeetCode #DSA #Java #Arrays #TwoPointers #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
-
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
-
-
🚀 Day 41 / 100 | Spiral Matrix II -Intuition: -The goal is to generate an n × n matrix filled with numbers from 1 to n^2 in spiral order. -Start from the top row, move right, then move down the right column, then move left across the bottom row, and finally move up the left column. -After completing one layer, shrink the boundaries and repeat the process until the matrix is filled. -Approach: O(n²) -Initialize an empty n × n matrix. -Maintain four boundaries: top, bottom, left, and right. -Start filling numbers from 1 to n^2. -Fill the top row from left -> right and move the top boundary down. -Fill the right column from top -> bottom and move the right boundary left. -Fill the bottom row from right ->left and move the bottom boundary up. -Fill the left column from bottom -> top and move the left boundary right. -Repeat the process until all elements are filled. -Complexity: Time Complexity: O(n²) Space Complexity: O(n²) #100DaysOfCode #Java #DSA #LeetCode #Matrix
To view or add a comment, sign in
-
-
Day 91/100 – LeetCode Challenge ✅ Problem: #98 Validate Binary Search Tree Difficulty: Medium Language: Java Approach: Inorder Traversal with Stack Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Inorder traversal of BST produces sorted ascending sequence. Compare each visited node with previous node to detect violations. Solution Brief: Used stack for iterative inorder traversal. Maintained pre pointer to track previous visited node. While traversing: Push all left nodes to stack Pop node, check if root.val <= pre.val (violation) Update pre to current node Move to right subtree #LeetCode #Day91 #100DaysOfCode #Tree #BST #Java #Algorithm #CodingChallenge #ProblemSolving #ValidateBST #MediumProblem #InorderTraversal #Stack #DSA
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
-
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