Day 4/100: Mastering the Two-Pointer Shuffle 🚀 💡 How I solved it: I used the Two-Pointer Technique to move all zeros to the end of an array while maintaining the original order of other elements. *Pointer i: Tracks the next position for a non-zero element. *Pointer j: Scans through the entire array. *The Swap: Every time j finds a non-zero value, it swaps with i. This effectively "bubbles" all zeros to the back in a single pass. 🧠 Key Takeaway: *Efficiency: Achieved O(n) time complexity and O(1) space (In-place modification). *Relative Order: This method ensures that non-zero numbers stay in their original sequence without needing extra memory or hash maps. The logic is getting sharper every day! 📈 #DSA #Python #100DaysOfCode #ProblemSolving #StriverA2Z
Move Zeroes to End of Array in Place
More Relevant Posts
-
🚀 Day 39/100 – LeetCode Challenge Today’s problem: 406. Queue Reconstruction by Height This problem focuses on applying a Greedy approach with sorting to reconstruct a queue based on height and positional constraints. 🔍 Key Insight: Sort people by height in descending order and k value in ascending order, then insert each person at their respective index. 💡 What I learned: Importance of sorting strategy in greedy problems How insertion at a specific index can maintain constraints Thinking from the perspective of "who affects whom" (taller vs shorter) 🧠 Approach: Sort the array → (-height, k) Insert each person at index k 💻 Code (Python): class Solution: def reconstructQueue(self, people): people.sort(key=lambda x: (-x[0], x[1])) queue = [] for p in people: queue.insert(p[1], p) return queue ⏱️ Time Complexity: O(n²) Consistency is the key — showing up every day and improving step by step. #Day39 #LeetCode #100DaysOfCode #DSA #Python #CodingChallenge #GreedyAlgorithm #SoftwareDevelopment
To view or add a comment, sign in
-
-
LeetCode Day 13 – Container With Most Water Today I solved the classic “Container With Most Water” problem — a great example of optimizing from brute force to an efficient solution! Problem Insight: We are given an array of heights, and we need to find two lines that together with the x-axis form a container that holds the maximum water. Approaches: Brute Force (O(n²)) Check all possible pairs Calculate area = width × min(height[i], height[j]) Keep track of maximum Optimal Approach – Two Pointer (O(n)) Start with two pointers at both ends Calculate area Move the pointer with smaller height inward Repeat until pointers meet Key Idea: The limiting factor is always the smaller height Moving the larger height won’t help increase area Complexity: Time: O(n) Space: O(1) What I learned: How two-pointer technique drastically reduces complexity Importance of understanding constraints before coding #LeetCode #Day13 #DSA #CodingJourney #Python #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 51 of #100DaysOfCode 📌 LeetCode 567 – Permutation in String 🔍 Problem Understanding We are given two strings s1 and s2. The task is to check whether any permutation of s1 exists as a substring in s2. In simple terms: If we rearrange the characters of s1, can we find that arrangement inside s2? 💡 Approach / Intuition The efficient way to solve this problem is using the Sliding Window Technique. Steps of thinking: 1️⃣ Count the frequency of characters in s1. 2️⃣ Create a window in s2 with the same size as s1. 3️⃣ Move the window one character at a time across s2. 4️⃣ For each window, compare the character frequencies with s1. 5️⃣ If the frequencies match, it means a permutation of s1 exists in s2. ⚡ Key Concepts Used Sliding Window Hash Map / Character Frequency Count String Traversal 📊 Complexity ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (since character set is fixed) #Day51 #100DaysOfCode #LeetCode #DSA #Python #CodingJourney #ProblemSolving #SlidingWindow
To view or add a comment, sign in
-
-
🚀 Day 163 of My LeetCode Journey 🚀 416. Partition Equal Subset Sum 🫧 We are given an array of integers and need to determine whether it can be split into two subsets with equal sum. ▪️ First, we calculate the total sum of the array. If the sum is odd, it cannot be divided into two equal parts, so return False. ▪️ If the sum is even, the problem becomes finding a subset whose sum equals total/2. ▪️ Treat this as a subset sum problem, where we check if we can form the target sum using the given numbers. ▪️ Our DP state is defined as (i, target), which represents whether we can form the target sum using elements from index. ▪️ At each index, we have two choices: either pick the element or not pick it. ▪️ If we pick the element, we reduce the target by nums[i]; if we skip it, the target remains the same. ▪️used memoization (dp[i][target]) to store results and avoid recomputing the same. ▪️ If successfully found a subset with a sum of total/ 2, it means the remaining elements automatically form the other subset with the same sum. #LeetCode #DynamicProgramming #Python #CodingJourney #Day163 🔥
To view or add a comment, sign in
-
-
Day 68 of 365 Days of code Qn 1) Min stack Approach: use an extra stack(to store minimum element up to the particular index) for push: push the value into the stack, check if the val is lesser than the element at the top of minstack, if yes, push the value, else push the copy of the top element in minstack for pop: pop from both of the stacks for returnmin: return minstack[top] :) good night #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
🚀 Day 32/60 — LeetCode Discipline Problem Solved: Find the Index of the First Occurrence in a String Difficulty: Easy Today’s problem was about locating a substring within a string — a classic example of pattern searching. Using a straightforward approach, I iterated through the string and checked each possible starting point where the substring could match. This reinforces how simple logic, when applied cleanly, can be highly effective. 💡 Focus Areas: • Strengthened understanding of string traversal • Practiced substring comparison • Improved handling of boundary conditions • Learned importance of index-based iteration • Focused on writing clean and readable code ⚡ Performance Highlight: Achieved 0 ms runtime (100% performance) Sometimes the answer isn’t hidden deep — it’s right there… waiting for a careful eye to notice it. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Python #Developers #Consistency #TechGrowth
To view or add a comment, sign in
-
-
Topic 10/100 🚀 🧠 Topic 10 — Partial Functions What if you could pre-fill some arguments of a function and reuse it later? 🤯 👉 What is it? Partial functions allow you to fix a few arguments of a function and generate a new function with fewer parameters. 👉 Use Case: Used in real-world applications for: Pre-configuring functions Simplifying repeated function calls Building reusable utilities 👉 Why it’s Helpful: Reduces repetition Makes code cleaner Improves readability 💻 Example: from functools import partial def multiply(x, y): return x * y double = partial(multiply, 2) print(double(5)) # Output: 10 🧠 What’s happening here? We fixed the value of x = 2, creating a new function (double) that only needs one argument. ⚡ Pro Tip: Use partial functions when you find yourself passing the same arguments repeatedly. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 169 of My LeetCode Journey 🚀 1092. Shortest Common Supersequence 🫧 In this problem, we are given two strings, and we need to build the shortest string that contains both of them as subsequences. ▪️ The key idea is related to the Longest Common Subsequence. If both strings share some common characters in order, we should include those characters only once in the final string. ▪️ First, I built a DP table to find the LCS length between the two strings. This helps us understand which characters are common between them. ▪️ After filling the DP table, I traversed it backwards to construct the final string. ▪️ If characters in both strings match, I add that character once to the result and move diagonally in the table. ▪️ If they don’t match, I move in the direction that gave the larger LCS value and add that character to the result. ▪️ If one string finishes before the other, I simply added the remaining characters from the other string. ▪️ In the end, I reversed the collected characters to get the shortest common supersequence, which contains both strings while keeping the length as small as possible. #LeetCode #DynamicProgramming #Strings #Python #CodingJourney #Day169 🔥
To view or add a comment, sign in
-
-
Day 3 / 100 🚀 Solved “Reverse Integer” — a problem that looks simple but actually tests how carefully you handle edge cases. At first, reversing digits feels straightforward. But the real challenge is handling 32-bit overflow without using extra space. 💡 Key learning: Before updating the result, always check if multiplying by 10 will exceed the allowed range. Core idea: rev * 10 + digit must stay within [-2³¹, 2³¹ - 1] Highlights: • Time Complexity: O(log n) • Space Complexity: O(1) • Correctly handles negative numbers and overflow This problem reinforced a critical habit: Don’t just make the logic work — validate boundary conditions. #100DaysOfCode #LeetCode #DSA #Python #ProblemSolving #CodingInterview
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