🚀 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
Reconstructing a Queue with Greedy Approach
More Relevant Posts
-
📈 Day 53 of #GeekStreak60 🧩 Today’s problem was about checking whether a matrix is a Toeplitz Matrix. 🧠 Core Idea Every element should match its top-left diagonal neighbor ↖️ If all such pairs match → the matrix is Toeplitz ✅ 💡 What I Did ➡️ Traversed the matrix starting from (1,1) ➡️ Compared each element with its top-left neighbor mat[i-1][j-1] 🔍 ➡️ Returned ❌ false immediately if any mismatch was found 📚 What I Learned ✨ Simple observations about patterns (like diagonals) can lead to clean and efficient solutions ✨ You don’t always need complex logic — sometimes local checks are enough! 🔥 Day 53 complete Consistency + clarity = growth 🚀 #GeekStreak60 #GeeksforGeeks #NPCI #Day53 #ProblemSolving #Python #CodingJourney
To view or add a comment, sign in
-
-
Today: LeetCode 88 — Merge Sorted Array. Saw "sorted arrays" in the problem. My brain immediately said: two pointers. Started coding. Got stuck pretty fast. The issue? When you're merging into an existing array without extra space, two pointers aren't enough — you need a third one tracking where to place elements. And you have to go backwards through nums1, or you'll overwrite values you still need. Took longer than I'd like to admit. Used hints. Eventually got it — and it beat 100% on runtime. The real lesson wasn't the algorithm. It was this: pattern recognition gets you to the door, but you still have to figure out which version of the pattern fits. "Two pointers" is a family of techniques, not a single move. Knowing the name isn't the same as understanding the shape of the problem. Day 36 of #1000DaysOfLearning #DSA #Python #LearningInPublic
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 36 – LeetCode Journey Today’s problem: String to Integer (atoi) ✔️ Handled leading spaces and signs (+/-) ✔️ Processed numeric characters step by step ✔️ Managed overflow conditions within 32-bit integer range 💡 Key Insight: Carefully handling edge cases (like spaces, signs, and overflow) is just as important as the core logic. Small conditions can make a big difference in correctness. This problem strengthened my understanding of string parsing, edge cases, and boundary conditions. Learning to write robust and reliable code every day 💪🔥 #LeetCode #Day36 #Strings #EdgeCases #Python #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
If you're using a list comprehension just to pass results into functions like sum() or max(), those brackets might be unnecessary. Dropping them turns it into a generator, so Python processes each value on demand instead of storing everything in memory. ✅ Same result with less overhead—which is especially noticeable with large datasets. Use brackets when you actually need a list, skip them when you don’t. Check out this week's edition of #PythonTips Tuesday!
To view or add a comment, sign in
-
Day 37 & 38 complete! 🚀 Finding Minimum and Maximum in an Array: Practiced single-pass iterations to identify the extreme values in a dataset, focusing on minimizing comparisons. Count Each Vowel in a String: Used a dictionary to map and count the frequency of vowels. This was great practice for handling case sensitivity and string traversal. First Unique Character in a String: Implemented a two-pass approach—first using a Hash Map to store character frequencies, and then iterating to find the first character with a count of one. Sometimes going back to the basics is the best way to ensure your logic is bulletproof! 📈 #100DaysOfCode #Python #DSA #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
day 25 [no zero days] 1. Cyberwire daily [https://lnkd.in/e7AfVXVy] wrapping RSAC 2026... 2. Darknet diaries ep 4 [https://lnkd.in/eyECZnq2] Talk Talk hack... 3. Python: Automate the boring stuff with Python > chapter 2 - IF-Else & Flow Control, Boolean values [True/False], comparison operators [relational operators], Boolean operators [and/or/not], components of flow control [conditions, blocks of code], flow control statements [if/else/elif], quiz #day25 #nozerodays #100daygoal
To view or add a comment, sign in
-
🚀 Day 83 of #100DaysOfCode 📌 Problem Solved: Letter Combinations of a Phone Number (LeetCode 17) Today’s challenge was all about exploring backtracking and how recursive decision-making builds combinations efficiently. 🔍 Given a string of digits (2–9), the goal is to generate all possible letter combinations based on the classic phone keypad mapping. 💡 Key Learning: Instead of trying every possible string blindly, backtracking helps us build combinations step-by-step and explore only valid paths — making the solution clean and efficient. ⚡ Highlights: ✔️ Used recursion to explore all possibilities ✔️ Implemented a digit-to-letter mapping ✔️ Built combinations incrementally ✔️ Achieved optimal runtime performance 📈 Result: ✅ All test cases passed ⚡ 0 ms runtime (Beats 100%) Consistency is starting to compound — one problem at a time. 💪 #LeetCode #DSA #Python #CodingJourney #Backtracking #100DaysOfCode
To view or add a comment, sign in
-
-
🚀Day-7 LeetCode Problem Solved – #3 Longest Substring Without Repeating Characters Today I solved one of the most popular Sliding Window problems on LeetCode: Longest Substring Without Repeating Characters 💡 Problem Summary: Given a string, find the length of the longest substring without any repeating characters. 🔍 Approach Used: I solved this using the Sliding Window + HashSet technique. The idea is to maintain a window of unique characters using two pointers: - left → start of the window - right → end of the window - set → stores current unique characters Whenever a duplicate character appears, I move the left pointer until the duplicate is removed, while continuously tracking the maximum length. ✨ Key Learning: This problem helped me strengthen my understanding of: - Sliding Window - Two Pointers - HashSet / Set operations - Time complexity optimization ⚡ Complexity: Time: O(n) Space: O(n) Every problem solved is one step closer to mastering DSA and problem-solving skills 💻 #LeetCode #DSA #Python #ProblemSolving #CodingJourney #SoftwareDeveloper #SlidingWindow #100DaysOfCode #InterviewPreparation
To view or add a comment, sign in
-
-
Day 3 of #50DaysDSA Problem Solved: Reverse Vowels of a String Today’s problem focused on efficient string manipulation using the two-pointer technique, a fundamental approach in algorithm design. Problem Statement: Given a string, reverse only the vowels while keeping all other characters in their original positions. Approach: Used two pointers (start and end) to traverse the string Identified vowels using a set for constant-time lookup Swapped vowels in-place while skipping non-vowel characters Continued until both pointers met Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) (due to string-to-list conversion in Python) Key Takeaway: This problem reinforces how a well-applied two-pointer strategy can lead to clean and optimal solutions without unnecessary data structures. #DSA #DataStructures #Algorithms #Python #SoftwareDevelopment #CodingPractice #Leetcode75 LeetCode Dhanraj Sahu
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