🚀 Day 9/30 – Handling Edge Cases in Array Manipulation Today’s problem involved incrementing a number represented as an array of digits. At first glance, it seems simple — just add one. But the real challenge lies in handling carry-over properly, especially in cases like: [1,2,3] → [1,2,4] [9,9,9] → [1,0,0,0] Instead of converting the array into an integer (which could cause overflow for large inputs), I processed the digits directly from right to left: Start from the last index Add one Handle carry propagation If all digits turn to zero, create a new array with an extra leading digit This keeps the solution clean and scalable. 📊 Performance ✅ All test cases passed ⚡ 0 ms runtime (100% performance) ⏱ O(n) time complexity 📦 O(1) extra space (excluding output array) 📚 Key Takeaway Small problems often test clarity of logic more than algorithmic complexity. Careful handling of edge cases makes solutions robust. Nine days in — building problem-solving discipline step by step. #Day9 #30DaysOfCode #LeetCode #Java #Algorithms #ArrayManipulation #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
Handling Array Edge Cases in Incrementing Numbers
More Relevant Posts
-
🚀 Day 11/30 – Working with Numbers Without Converting to Strings Today’s problem involved checking whether a given integer is a palindrome. While one straightforward approach would be converting the number into a string and reversing it, I chose to solve it mathematically — by reversing the digits of the number itself. 💡 Approach Immediately return false for negative numbers Store the original number Reverse the digits using modulo (% 10) and division (/ 10) Compare the reversed number with the original This avoids unnecessary string conversion and keeps the logic purely numerical. 📊 Performance ✅ All test cases passed ⚡ Efficient runtime ⏱ O(log₁₀ n) time complexity 📦 O(1) space complexity 📚 Key Takeaway Sometimes the better solution isn’t the easiest one — it’s the one that respects constraints and demonstrates deeper understanding of number manipulation. Day 11 complete. Building stronger fundamentals, one problem at a time. #Day11 #30DaysOfCode #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
Analysing a thread dump can get messy. Hundreds of lines. Repeated stack traces. Waiting, blocked, runnable — all blended into what feels like noise. But here’s a better way to look at it: A thread dump is not just text. It’s a snapshot. Now imagine it as a frame from a video. One frame alone won’t tell you the full story. But when you line up multiple thread dumps — taken a few seconds apart — you start connecting the dots. You begin to see: • Which threads are stuck in the same place • Which locks are being contended repeatedly • Which operations never move forward • Whether the system is frozen… or just busy Suddenly, it’s not chaos. It’s motion. You’re not reading logs anymore — you’re watching behavior. That shift in perspective changes everything. Instead of asking, “What is this thread doing?” You start asking, “What story is the system telling across frames?” And that’s when root causes start revealing themselves. Debugging is rarely about a single snapshot. It’s about observing patterns over time. Next time a thread dump feels overwhelming, don’t try to decode it all at once. Turn it into a movie. 🎬 Watch the frames. Connect the dots. That’s where the real insights live. #PerformanceEngineering #Java #Debugging #Theeaddumps
To view or add a comment, sign in
-
🚀 Day 10/30 – Strengthening String Processing Fundamentals Today’s problem focused on determining whether two strings are anagrams of each other. Instead of sorting both strings (which would take O(n log n) time), I implemented a frequency-count approach using a fixed-size array to track character occurrences. 💡 Approach First, check if the lengths differ — if so, they cannot be anagrams. Use an integer array of size 26 (for lowercase letters). Increment counts for characters in the first string. Decrement counts for characters in the second string. If all values return to zero, the strings are valid anagrams. This approach ensures: ⏱ O(n) time complexity 📦 O(1) space complexity (constant size array) 📊 Performance ✅ All test cases passed ⚡ Efficient runtime 💾 Optimized space usage 📚 Key Takeaway Optimizing from a sorting-based solution to a frequency-count approach highlights the importance of understanding constraints. Sometimes improving complexity from O(n log n) to O(n) is not about writing more code — it's about choosing the right idea. Ten days completed. Small improvements every day compound over time. #Day10 #30DaysOfCode #LeetCode #Java #Algorithms #StringManipulation #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 20/30 – Making Strings Valid with Minimum Removals Today’s problem focused on removing the minimum number of parentheses to make a string valid. What made it interesting was balancing correctness with efficiency while preserving the original character order. 💡 Approach Traverse the string and track unmatched parentheses Mark invalid positions instead of rebuilding the string repeatedly Construct the final result in a single pass This ensures: ⏱ O(n) time complexity 📦 O(n) space complexity 📊 Performance ✅ All test cases passed ⚡ 5 ms runtime (Beats 99.89%) 💾 Efficient memory usage 📚 Key Takeaway This problem strengthened my understanding of: Using stacks / counters for validation Avoiding unnecessary string reconstruction Thinking in terms of minimum removals instead of full recomputation 🔍 What I Would Optimize Next Exploring alternate implementations that reduce auxiliary space while keeping the logic readable. 🎯 Day 20 complete – 2/3 of the challenge done. The focus now is on solving Medium problems faster and recognizing patterns earlier. #Day20 #30DaysOfCode #LeetCode #Java #Algorithms #Stacks #StringManipulation #ProblemSolving #InterviewPreparation #SoftwareEngineering #CodingJourney #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 13/30 – Tracking Patterns in Arrays Today’s problem focused on finding the maximum number of consecutive 1’s in a binary array. While the logic is straightforward, the key is identifying and tracking streaks efficiently without using extra space. 💡 Approach Traverse the array once Maintain a running counter for consecutive 1’s Reset the counter when a 0 is encountered Continuously track the maximum streak using Math.max() This ensures: ⏱ O(n) time complexity 📦 O(1) space complexity 📊 Performance ✅ All test cases passed ⚡ Efficient runtime 💾 Constant space usage 📚 Key Takeaway Problems like this reinforce an important idea: Many array questions are about recognizing patterns and maintaining state correctly during traversal. Even simple problems sharpen attention to iteration logic and edge handling. Day 13 complete. Consistency + clarity = steady improvement. #Day13 #30DaysOfCode #LeetCode #Java #Algorithms #ArrayProblems #ProblemSolving #SoftwareEngineering #CodingJourney #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode #48 – Rotate Image Solved the classic matrix problem where we rotate an n × n matrix by 90° clockwise, and the challenge is to do it in-place without using extra space. Instead of creating a new matrix, I used a 2-step optimized approach: 1️⃣ Transpose the matrix (swap matrix[i][j] with matrix[j][i]) This converts rows into columns by swapping elements across the diagonal. 2️⃣ Reverse each row After transposing, reversing every row completes the 90° clockwise rotation. This approach keeps the solution clean and efficient: ⏱ Time Complexity: O(n²) 📦 Space Complexity: O(1) (no extra matrix used) A great problem to strengthen the understanding of matrix manipulation, indexing, and in-place transformations. #LeetCode #ProblemSolving #DataStructures #Java #CodingJourney
To view or add a comment, sign in
-
-
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 🚀
To view or add a comment, sign in
-
-
Day 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
Most people would return this answer: [2, 2] But the correct answer is: [2] Why? 🚀 Day 64/365 — DSA Challenge Solved: Intersection of Two Arrays The task: Given two arrays, return their intersection. But there are two conditions: • The element must exist in both arrays • The result must contain only unique values Example: nums1 = [1,2,2,1] nums2 = [2,2] Output: [2] Even though 2 appears multiple times, it should appear only once in the result. 💡 My Approach (Simple Logic) Step 1 Loop through every element of nums1. Step 2 Check if that number exists in nums2. Step 3 Before adding it to the result, make sure it hasn't already been added. To keep the code clean, I used three methods: intersection() Main method that loops through nums1 and builds the result. existsInArray(num, arr) Checks if a number exists in another array. existsInArray(num, arr, length) Checks duplicates only inside the filled part of the result array. Example walkthrough: 1 -> not in nums2 -> skip 2 -> exists -> add 2 -> already added -> skip 1 -> skip Final output: [2] ⏱ Time Complexity: O(n × m) 📦 Space Complexity: O(n) Day 64/365 complete. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #LearningInPublic #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 | 𝗗𝗲𝗹𝗲𝘁𝗲 𝗡𝗼𝗱𝗲 & 𝗥𝗲𝗺𝗼𝘃𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 Day 44 ✅ — Two deletion techniques, one day. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟯𝟳: Delete Node in a Linked List (Medium) ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟬𝟯: Remove Linked List Elements (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: 𝕯𝖊𝖑𝖊𝖙𝖊 𝕹𝖔𝖉𝖊 (#237): The twist? You're only given the node to delete—not the head. Can't access previous node. Solution: Copy next node's value to current, then skip next. Clever trick that feels like breaking the rules. 𝕽𝖊𝖒𝖔𝖛𝖊 𝕰𝖑𝖊𝖒𝖊𝖓𝖙𝖘 (#203): Remove all nodes with a specific value. The standard deletion problem—handle head separately, then traverse and skip matching nodes. Two problems, two deletion strategies. Both are in-place, O(1) space. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵𝗲𝘀: 𝑫𝒆𝒍𝒆𝒕𝒆 𝑵𝒐𝒅𝒆: 👉 Copy next node's value to current 👉 Skip next node: node.next = node.next.next 𝑹𝒆𝒎𝒐𝒗𝒆 𝑬𝒍𝒆𝒎𝒆𝒏𝒕𝒔: 👉 Handle head nodes with target value first 👉 Traverse and skip nodes matching value 👉 Return potentially new head Time: O(n), Space: O(1) for both 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Fifteen linked list problems (Day 30-44). Deletion patterns are now second nature. The "Delete Node" trick shows that sometimes the clever solution isn't what you'd expect. Challenge your assumptions. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gMb9bPNy 𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 ✅ | 𝟱𝟲 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #NodeDeletion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #InPlaceAlgorithm #Programming #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
🔥🔥