Day 100: Consistency, Growth, and a Milestone 💯 Problem 3740: Minimum Distance Between Three Equal Elements I Today marks 100 days of continuous problem-solving. While the number is just a marker, the real value has been the daily discipline of opening the IDE and tackling whatever challenge LeetCode throws my way. The Strategy: • Frequency Grouping: I used a HashMap to store a list of indices for every unique number in the array. This allowed me to isolate potential triplets instantly. • Sliding Window Logic: For any number appearing three or more times, I looked at a sliding window of three consecutive indices (i,i+1,i+2). • The Formula: Through testing, I identified that the minimum distance between three equal elements can be derived from the span between the first and third occurrence: (index of 3rd - index of 1st) * 2. • Optimization: By iterating through the pre-grouped index lists, I kept the solution efficient and clean. Reflecting on these 100 days, I’ve moved from basic simulations to complex optimizations like Square Root Decomposition and 3D DP. The goal isn't to stop here—it's to keep building, keep optimizing, and keep growing. 🚀 #LeetCode #Java #Algorithms #DataStructures #100DaysOfCode #Consistency #ProblemSolving #DailyCode
100 Days of Consistency and Growth in LeetCode
More Relevant Posts
-
🚀 Solved LeetCode 2515 – Shortest Distance to Target String in a Circular Array Today I tackled an interesting problem that highlights the importance of handling circular data structures efficiently. 🔍 Problem Insight: Given a circular array of words, a target string, and a starting index, the goal is to find the minimum number of steps required to reach the target by moving either left or right. 💡 Key Learnings: Circular arrays require thinking beyond linear traversal Always consider both directions (forward & backward) Optimizing distance using min(distance, n - distance) is the key trick Simple logic + correct observation = optimal solution ⚙️ Approach Used: Traverse the array to find all occurrences of the target Calculate distance from the starting index Take the minimum considering circular movement 📈 Complexity: Efficient O(n) solution with constant space 🔥 Takeaway: This problem reinforced how small tweaks (like circular behavior) can change the entire approach. A great example of combining logic + observation for clean and optimal solutions. #LeetCode #Algorithms #ProblemSolving #CodingJourney #Java #DataStructures #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 27 of my #30DayCodeChallenge: The Efficiency of Binary Exponentiation! The Problem: Pow(x, n). Implementing the power function to calculate x". While it sounds simple, the challenge lies in handling large exponents (up to 231 - 1) and negative powers without hitting time limits or overflow. The Logic: This problem is a classic example of Divide and Conquer optimized through Binary Exponentiation (also known as Exponentiation by Squaring): 1. Bitwise Breakdown: Instead of multiplying x by itself n times (O(n)), we decompose n into powers of 2. For example, x13 is x8. x4. x¹. This brings our complexity down to O(log n). 2. The Iterative Jump: In every iteration of the loop, we square the current base (x = x x). If the current bit of n is 1 (checked via n & 1), we multiply our result by the current base. 3. Handling the Edge Cases: * Negative Exponents: If n is negative, we calculate xI" and then take the reciprocal (1/result). Overflow: We use a long for n during calculation to avoid overflow when converting -2, 147, 483, 648 to a positive value. The Calculation: By halving the power at each step, we transform a task that could take 2 billion operations into one that takes just 31. One step closer to mastery. Onward to Day 28! #Java #Algorithms #DataStructures #BinaryExponentiation #ProblemSolving #150DaysOfCode #SoftwareEngineer
To view or add a comment, sign in
-
-
🚀 Day 56 of my #100DaysOfCode Journey Today, I solved LeetCode problem Reshape the Matrix Problem Insight: We are given a 2D matrix and two integers r and c. The task is to reshape the matrix into dimensions r × c while keeping the same elements in row-major order. If reshape is not possible, return the original matrix. Approach: • First, check if reshape is possible using condition → total elements must match (m × n == r × c) • Traverse the matrix using a single loop (treating it as a linear array) • Map old indices to new indices using division and modulo • Fill the new matrix in row-wise order Code Idea Used: Index mapping technique (1D simulation of 2D matrix) Time Complexity: O(m × n) | Space Complexity: O(1) (excluding output matrix) Key Takeaway: Understanding how to convert between 1D and 2D indexing (i/m, i%m) is very powerful for matrix transformation problems. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #100DaysOfCode #Arrays #MatrixProblems
To view or add a comment, sign in
-
-
Day 38 of My DSA Journey Today I solved LeetCode 152 – Maximum Product Subarray on LeetCode. 📌 Problem Given an integer array nums, find the contiguous subarray that has the largest product, and return that product. Example: Input: [2,3,-2,4] Output: 6 → subarray [2,3] 🧠 Approach – Dynamic Programming (Tracking Max & Min) This problem is tricky because of negative numbers. Key Idea: • At each index, we maintain: maxProduct → maximum product ending at current index minProduct → minimum product ending at current index 👉 Why min? Because a negative number can turn a small (negative) product into a large positive one. Steps I followed: • Initialize maxProduct, minProduct, and ans with the first element • Traverse the array from left to right • If the current number is negative → swap max and min • Update: maxProduct = max(current, current × maxProduct) minProduct = min(current, current × minProduct) • Update the final answer using maxProduct ⏱ Time Complexity: O(n) — Single pass through the array 📦 Space Complexity: O(1) — No extra space used 💡 Key Learnings ✔ Handling negative numbers in product problems ✔ Using dynamic programming with state tracking ✔ Understanding why tracking both max & min is important This is one of those problems that looks simple but tests deep understanding of edge cases 🚀 Consistency continues — leveling up every day 💪 #100DaysOfCode #DSA #DynamicProgramming #Arrays #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 22/50 💡 Approach: Space-Optimized Dynamic Programming A robot moves only RIGHT or DOWN on an m×n grid. How many unique paths reach the bottom-right corner? Recursion explodes exponentially — DP solves it beautifully, and we can do even better by ditching the full 2D grid! 🔍 Key Insight: → Every cell's paths = paths from ABOVE + paths from LEFT → First row & first column always have exactly 1 path each → We only ever need the CURRENT and PREVIOUS row → So one 1D array updated in-place is enough! 📈 Complexity: ❌ Recursion → O(2^(m+n)) Time ❌ 2D DP → O(m×n) Time, O(m×n) Space ✅ 1D DP → O(m×n) Time, O(n) Space Same speed, fraction of the memory! DP teaches us to build solutions from the ground up — one step, one row, one decision at a time. 🤖 #LeetCode #DSA #DynamicProgramming #Java #ADA #PBL2 #LeetCodeChallenge #Day22of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #UniquePaths
To view or add a comment, sign in
-
-
🚀 Day 30 of #100DaysOfCode Solved Trapping Rain Water 🌧️ One of those classic problems that really tests your ability to think beyond brute force. Instead of checking every pair, I used the prefix max (leftMax) and suffix max (rightMax) approach to efficiently calculate trapped water. 🔍 Key Takeaways: Precomputing left and right maximum heights simplifies the problem Water trapped at each index = min(leftMax, rightMax) − height[i] Turning intuition into optimized code is the real win here 💻 Complexity: Time: O(n) Space: O(n) Another step forward in mastering arrays and patterns 💪 #DSAwithEdSlash #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 37 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Transpose Matrix Problem Insight: Given a matrix, the task is to convert its rows into columns. If no transformation is possible in-place (for non-square matrices), we create a new matrix. Approach: • Identify number of rows and columns • Create a new matrix with reversed dimensions (col × row) • Traverse each element of the original matrix • Place elements by swapping indices → (i, j) becomes (j, i) Time Complexity: • O(m × n) — visiting each element once Space Complexity: • O(m × n) — due to new matrix creation Key Learnings: • Transpose = swapping row and column indices • Dimension handling is crucial to avoid errors • In-place transpose is only possible for square matrices Takeaway: A small change in indexing can completely transform how we view and solve a problem. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Matrix
To view or add a comment, sign in
-
-
🚀 Day 567 of #750DaysOfCode 🚀 🔍 Problem Solved: Maximum Distance Between a Pair of Values Today’s challenge was about finding the maximum distance (j - i) such that: ✔️ i ≤ j ✔️ nums1[i] ≤ nums2[j] ✔️ Both arrays are non-increasing 💡 Key Insight: Since both arrays are sorted in descending order, we can avoid brute force and use a Two Pointer approach to achieve optimal performance. 🧠 Approach: Initialize two pointers i and j at 0 If nums1[i] ≤ nums2[j] → valid pair → update distance & move j Else → move i forward Maintain j ≥ i at all times 📊 Complexity: Time: O(n + m) Space: O(1) 🔥 Takeaway: Whenever arrays are sorted, always think of two pointers or binary search before jumping to brute force. This simple shift can reduce complexity from O(n²) → O(n)! #Day567 #750DaysOfCode #LeetCode #Java #DataStructures #Algorithms #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfCode — Sliding Window Today, I worked on the problem “Max Consecutive Ones III” LeetCode. Problem Summary Given a binary array, the goal is to find the maximum number of consecutive 1s if you can flip at most k zeros. Approach At first glance, this problem looks like a brute-force or restart-based problem, but the optimal solution lies in the Sliding Window technique. The key idea is to maintain a window [i, j] such that: The number of zeros in the window does not exceed k Expand the window by moving j Shrink the window by moving i whenever the constraint is violated Instead of restarting the window when the condition breaks, we dynamically adjust it. Key Logic Traverse the array using pointer j Count the number of zeros in the current window If zeros exceed k, move pointer i forward until the window becomes valid again At every step, update the maximum window size Why This Works This approach ensures: Each element is processed at most twice Time Complexity: O(n) Space Complexity: O(1) The most important learning here is understanding how to dynamically adjust the window instead of resetting it, which is a common mistake while applying sliding window techniques. In sliding window problems, always focus on expanding and shrinking the window efficiently rather than restarting the computation. #100DaysOfCode #DSA #SlidingWindow #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 74/100 – LeetCode Challenge 🔍 Problem Solved: Find the Duplicate Number (287) Today’s problem was a great reminder that sometimes the best solutions come from thinking differently 💡 Instead of using extra space or modifying the array, I used Floyd’s Cycle Detection Algorithm (Tortoise & Hare) — treating the array like a linked list to detect a cycle. 👉 Key Learnings: • Arrays can sometimes be visualized as linked structures • Cycle detection is not just for linked lists! • Optimizing for O(1) space is a common interview expectation ⚡ Approach: Use two pointers (slow & fast) First, find intersection point Then, find the cycle start → duplicate number ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) ✅ Successfully passed all test cases! Consistency > Perfection. Let’s keep going 💪 #Day74 #LeetCode #100DaysOfCode #Java #CodingInterview #ProblemSolving #DataStructures #Algorithms
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