🚀 Day 51 of #100DaysOfCode — LeetCode + HackerRank Edition Today’s challenge: Spiral Matrix — traverse a matrix in spiral order and return the elements. 🌀🧩 Problem (brief): Given an m x n matrix, return all elements in spiral order (clockwise starting from top-left). 📌 My approach →Use four boundaries: top, bottom, left, right. →Walk: left→right along top, top→bottom along right, right→left along bottom, bottom→top along left. →After each traversal, move the corresponding boundary inward. →Repeat while top <= bottom and left <= right. →Handle edge cases: single row, single column, or empty matrix. 💡 What I learned today: ✅Boundary-driven traversal is a neat pattern — useful for many matrix problems. ✅Always check the top<=bottom and left<=right conditions before traversing opposite sides to avoid duplicates. ✅Dry runs are everything — they reveal off-by-one bugs faster than tests. Let’s share patterns — how do you solve Spiral Matrix? Do you prefer boundary pointers, or recursion (peel the outer layer)? Drop your implementation or edge cases — I’ll compare notes! 👇 #Day51 #100DaysOfCode #LeetCode #Python #DSA #SpiralMatrix #ProblemSolving #CodeNewbie #LearnInPublic
Solving Spiral Matrix with Boundary-Driven Traversal
More Relevant Posts
-
🚀 Day 26 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about string precision and pattern matching: 🔗 Implement strStr() (LeetCode) 📌 Challenge: Given two strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if it doesn’t exist. 🔍 Approach: → Skipped the built-in .find() to implement it manually → Iterated through haystack only up to len(haystack) - len(needle) → Compared slices haystack[i:i+len(needle)] with needle → Returned the index on match, -1 otherwise 💡 What made it click: → Realized that checking every possible starting index is enough — no need to build substrings manually → Adjusting the loop range to avoid out-of-bound errors was the key → Removing redundant checks like if needle not in haystack made the code cleaner and faster 📚 What I learned: ✅ Substring search is a great intro to sliding window logic ✅ Clean loop bounds = fewer bugs ✅ Sometimes the simplest approach is the most elegant ✅ Writing your own version of built-ins deepens your understanding of how they work under the hood Have you implemented your own strStr() before? Did you go brute-force or try KMP? Let’s compare strategies 💬🔍 #Day26 #LeetCode #StringMatching #CodingChallenge #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #geeksforgeeks #100DaysOfCode
To view or add a comment, sign in
-
-
💯 Day 40 / 100 – 100 Days of #LeetCode Challenge 🔁 Problem: 674. Longest Continuous Increasing Subsequence Goal: Given an unsorted array of integers nums, find the length of the longest continuous increasing subsequence (subarray) — the numbers must be strictly increasing and appear consecutively. Approach: ✅ Initialize two variables — currLen for the current increasing streak and long for the longest found so far. ✅ Traverse the array and compare each element with the previous one. ✅ If current > previous, increase currLen and update long. ✅ Otherwise, reset currLen to 1. ✅ Return long as the final answer. Complexity: ⏱ Time: O(n) – Single pass through the array. 🗂 Space: O(1) – Constant extra space. 💡 Key Takeaways: A simple iteration can efficiently handle continuous subarray problems. Keeping track of streaks is a common pattern in array-based challenges. Great for practicing iteration, condition handling, and edge cases. #100DaysOfLeetCode #Day40 #Python #DSA #CodingChallenge #ProblemSolving #LeetCode #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 45 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a deep dive into recursion and backtracking 🔁🧠 🧩 permute(self, nums: List[int]) -> List[List[int]] — Generate all possible permutations of a list of distinct integers. 📌 Challenge: → Given a list nums, return all possible orderings → Each number must appear exactly once per permutation → Example: nums = [1, 2, 3] ✅ Output: [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] 🔍 Approach: → Use recursion to build permutations step-by-step → Track current path with curr → Skip numbers already in curr → When len(curr) == len(nums), add a copy to results → Backtrack by popping the last element 💡 What made it click: → Visualized the recursive tree — each level adds one unused number → Practiced dry runs with nums = [1, 2, 3] to see how paths evolve → Realized how curr.pop() resets the state for the next branch → Appreciated how backtracking avoids duplicate paths and keeps memory clean 📚 What I learned: ✅ How to implement recursive backtracking with minimal state ✅ How to use dry runs to trace recursive calls ✅ How to visualize tree-like expansion of choices ✅ The power of copying lists (curr[:]) to preserve snapshots Have you ever visualized recursion like a decision tree? Let’s swap strategies and dry run walkthroughs 💬 #Day45 #Leetcode #Python #Recursion #Backtracking #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 46 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a twist on yesterday’s recursion puzzle — this time with duplicates in the mix 🔁🧠 🧩 permuteUnique(self, nums: List[int]) -> List[List[int]] — Generate all unique permutations of a list that may contain duplicate integers. 📌 Challenge: → Given a list nums, return all distinct orderings → Each number must appear exactly once per permutation → Example: nums = [1, 1, 2] ✅ Output: [[1,1,2], [1,2,1], [2,1,1]] 🔍 Approach: → Sort the input to group duplicates → Use recursion + backtracking to build paths → Track visited indices with a used[] array → Skip duplicates using: if i > 0 and nums[i] == nums[i - 1] and not used[i - 1]: continue → Backtrack by popping the last element and resetting used[i] 💡 What made it click: → Visualized the decision tree for [1, 1, 2] — saw how pruning avoids duplicate branches → Practiced dry runs to trace how used[] and sorting work together → Realized how skipping nums[i] when nums[i] == nums[i-1] and used[i-1] == False prevents redundant paths → Appreciated how recursion + pruning = clean, efficient, elegant 📚 What I learned: ✅ How to handle duplicates in permutation problems ✅ How sorting + index tracking helps prune recursion ✅ How to visualize branching decisions and avoid redundant paths ✅ The subtle power of used[] and index-based duplicate checks Have you ever debugged a recursive tree with duplicate values? Let’s swap strategies, dry runs, and visual walkthroughs 💬 #Day46 #Leetcode #Python #Recursion #Backtracking #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfCode —Leetcode + HackerRank Edition! Today’s challenge was a classic logic puzzle wrapped in a deceptively simple interface: 🧩 isValidSudoku(board: List[List[str]]) — Validate a partially filled Sudoku board. 📌 Challenge: Check whether a 9×9 Sudoku board is valid so far, based on three rules: → Each row must contain digits 1–9 without repetition → Each column must contain digits 1–9 without repetition → Each 3×3 sub-box must contain digits 1–9 without repetition 🔍 Approach: → Used three dictionaries of sets to track digits in rows, columns, and boxes → Iterated through each cell, skipping empty ones ('.') → For each digit, checked if it already exists in the corresponding row, column, or box → If duplicate found → return False; otherwise → add to all three sets 💡 What made it click: → Realized that each 3×3 box can be indexed using (i // 3, j // 3) — a neat trick! → Avoided nested loops or extra flags by using clean set logic → Practiced writing readable validation logic that mirrors real-world constraints 📚 What I learned: ✅ How to track multi-dimensional constraints using dictionaries of sets ✅ The power of clean iteration and early returns for validation problems ✅ Sudoku is a great playground for practicing control flow, indexing, and set operations Have you tackled this one before? Did you use sets, arrays, or something else entirely? Let’s swap strategies 💬 #Day38 #HackerRank #Python #SudokuLogic #ValidationChallenge #ControlFlow #ProblemSolving #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode#DSA
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about frequency mapping and subarray logic — solving the Picking Numbers problem from HackerRank. 🔗 Problem: pickingNumbers(a) (HackerRank) 📌 Challenge: Given an array of integers, find the length of the longest subarray where the absolute difference between any two elements is ≤ 1. 🔍 Approach: → Used Python’s Counter to map frequencies of each number → For each number num, calculated freq[num] + freq[num + 1] → Tracked the maximum such sum to find the longest valid subarray → Avoided brute-force by leveraging frequency patterns instead of scanning all subarrays 💡 What made it click: → Realized that valid subarrays must contain only num and num + 1 → Frequency mapping reveals hidden structure in the data → Clean logic with max() and get() made the solution elegant and readable 📚 What I learned: ✅ Frequency-based thinking can simplify subarray problems ✅ Counter is a powerful tool for pattern detection ✅ Avoiding brute-force leads to scalable, efficient solutions ✅ Sharing dry runs and visual walkthroughs helps others grasp the intuition faster Have you tackled Picking Numbers before? Did you go with sorting, brute-force, or frequency mapping like I did? Let’s swap strategies 💬 #Day31 #HackerRank #SubarrayLogic #FrequencyMapping #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
💡 Day 40 / 100 – Letter Combinations of a Phone Number (LeetCode #17) Today’s challenge was about generating all possible letter combinations from a string of digits on a phone keypad. This problem blends recursion and backtracking, testing both logic and creativity. Each digit maps to a set of letters (like on an old mobile keypad), and the goal is to explore every possible letter combination that could be formed. The key is to use recursion effectively — adding one letter at a time and exploring deeper until the combination is complete. 🔍 Key Learnings Recursion builds combinations step-by-step with clean logic. Backtracking helps explore multiple paths efficiently without redundant work. Using base conditions effectively keeps recursion under control and prevents infinite loops. 💭 Thought of the Day Sometimes, complex problems can be solved by thinking recursively — one small step at a time. This challenge reminded me that big results are just the outcome of many small, consistent actions — just like our 100 days of code journey. 🔗 Problem Link: https://lnkd.in/gUuS6Zp6 #100DaysOfCode #Day40 #LeetCode #Python #Recursion #Backtracking #ProblemSolving #CodingChallenge #Algorithms #DataStructures #CleanCode #PythonProgramming #LogicBuilding #KeepLearning #CodingJourney
To view or add a comment, sign in
-
-
🧠 Day 44 / 100 – Product of Array Except Self (LeetCode #238) Today’s challenge was all about computing an array where each element is the product of all numbers except itself — without using division. This one teaches prefix and suffix logic beautifully. The trick is to build two running products: One from the left (prefix) One from the right (suffix) Then combine both to get the final result. No division needed, no nested loops — just clean, efficient logic. 🔍 Key Learnings Use prefix and suffix multiplications for O(n) time complexity. Avoid division to handle zero cases efficiently. Think about how to reuse partial results rather than recomputing them. 💭 Thought of the Day Efficiency comes from rethinking the obvious. Instead of brute-forcing every combination, using prefix and suffix logic shows how planning ahead can simplify everything. Each day, I’m learning to design solutions, not just write them. 🔗 Problem Link: https://lnkd.in/gbGfa4dd #100DaysOfCode #Day44 #LeetCode #Python #Arrays #PrefixSum #ProblemSolving #Algorithms #DataStructures #EfficientCoding #CodeEveryday #LearningJourney #TechGrowth #CleanCode
To view or add a comment, sign in
-
-
🚀 Day 52 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was all about bringing order to chaos — merging overlapping intervals into clean, non-overlapping ranges 🗂️✨ 🧩 def merge(self, intervals: List[List[int]]) -> List[List[int]]: — Combine overlapping intervals into a simplified list 📌 Challenge: → Implement a function to merge overlapping intervals → Avoid brute-force approaches that check every pair → Optimize for clarity and performance 🔍 Approach: → First, sort intervals by their start time → Keep track of the last merged interval (prev[0]) → If the current interval overlaps, extend the end boundary → Otherwise, add it as a new interval 💡 What made it click: → Realized sorting upfront makes merging straightforward → Saw how prev[1] = max(prev[1], interval[i][1]) elegantly handles overlaps → Practiced dry runs with examples like: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]] 📚 What I learned: ✅ Why sorting is the key to simplifying interval problems ✅ How greedy merging avoids unnecessary comparisons ✅ How to handle edge cases like single intervals or fully nested ranges Ever felt like your calendar was a mess of overlapping meetings? This algorithm is the perfect organizer 🗓️😎 Let’s swap dry runs, edge cases, and interval insights 💬 #Day51 #Leetcode #Python #MergeIntervals #GreedyAlgorithm #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🧠 Day 13 — Thinking in Ranges, Not Just Numbers Today’s LeetCode problem was “Maximum Frequency of an Element After Performing Operations I.” At first, it felt straightforward — perform up to numOperations changes on elements within a range of [-k, k] to maximize frequency. But once I got into it, I realized the real challenge wasn’t the operations — it was understanding how intervals overlap and interact. Here’s the logic I built around it: 🔹 Each number can shift within [num - k, num + k], forming a range of possible values. 🔹 The goal is to find how many such ranges overlap at any point — that overlap represents the maximum achievable frequency. 🔹 I used sorted events and a sweep line approach to track how many intervals are active at any moment. 🔹 The maximum overlap gives the answer — the highest number of elements that can become equal after allowed operations. This problem wasn’t just about code; it was about thinking visually — seeing numbers as segments on a line rather than static values. That shift in perspective changed how I approached it. Thanks to Shishir chaurasiya sir and PrepInsta team One more day, one more layer of understanding peeled back. #Day13 #LeetCode #ProblemSolving #100DaysOfCode #Python #Algorithms #DataStructures #KeepBuilding #DevMindset
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