🚀 Day 69/100 – DSA Challenge Another day, another step closer to mastery 💯 Today’s problem was about finding the maximum distance between two houses with different colors. 🔍 Problem: Given an array where each element represents the color of a house, find the maximum distance between two houses such that their colors are different. 🧠 Approach: Instead of checking all pairs (which would be inefficient), the key idea is: Compare elements from the start with the end Find the farthest positions where colors differ Maximize the distance using smart observations rather than brute force 💡 Key Insight: The maximum distance will always involve either the first or the last house — this reduces the problem from quadratic to linear time. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 📌 Learning: This problem reinforced how identifying patterns and constraints can help avoid brute force and lead to optimal solutions. Consistency streak continues 🔥 On to Day 70 🚀 #100DaysOfCode #DSA #Java #ProblemSolving #Consistency #CodingJourney #KeepLearning
Max Distance Between Different Color Houses in Array
More Relevant Posts
-
Day 75 of My DSA Journey Today’s problem: Reverse Bits (LeetCode 190) At first glance, it looks simple—but it really tests your understanding of bit manipulation 🔹 What I learned today: • How to extract the last bit using n & 1 • Building a reversed number using left shift • Importance of running exactly 32 iterations (handling leading zeros!) • Thinking in terms of binary, not decimal 🔹 Key Idea: Take bits from right to left and rebuild the number from left to right. 💡 This problem helped me get more comfortable with low-level operations—something that’s super useful for writing efficient code. 📈 Progress Update: 75 days of consistency! Small steps every day are building strong problem-solving skills #DSA #100DaysOfCode #Java #CodingJourney #LeetCode #BitManipulation #Consistency #Learning
To view or add a comment, sign in
-
-
🚀 Day 99 of DSA Problem Solving Today’s problem: Word Pattern (LeetCode 290) At first glance, this problem looked simple — just matching characters with words. But the real challenge was ensuring a bijective mapping (one-to-one relationship) between pattern characters and words. 🔍 Problem Idea: We need to check if each character in the pattern maps to exactly one word in the string, and each word maps back to only one character. 💡 Key Learning: One-directional mapping is NOT enough We must ensure two-way consistency (character → word AND word → character) HashMaps are powerful for maintaining this mapping efficiently 🧠 Concepts Practiced: HashMap usage String manipulation (split) Bijective mapping logic ⏱ Time Complexity: O(n), where n = number of words 💭 Real Journey Behind the Solution: Initially, I thought using just one HashMap would work, but that led to incorrect mappings. Then I realized the importance of maintaining two HashMaps to ensure no duplication from either side. This problem strengthened my understanding of mapping relationships — a small concept but very powerful in many DSA problems. 🔥 Slowly getting better every day… consistency is the real game. #Day99 #DSA #LeetCode #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 142/360 – Learning Something New Today 🚀 Most people miss this simple trick… But once you understand it, problems become much easier 👇 📌 Topic: Bit Manipulation 🧩 Problem: Single Number II 📝 Problem Statement: Find the element that appears once when all others appear three times 🔍 Example: Input: [2, 2, 3, 2] Output: 3 💡 Approach: Bit Manipulation (Bit Counting) ✔ Step 1 – Traverse all 32 bit positions ✔ Step 2 – Count how many numbers have that bit set ✔ Step 3 – If count % 3 == 1, set that bit in answer ⚡ Key Idea: Duplicate numbers contribute bits in multiples of 3, so taking modulo 3 isolates the unique number ⏱ Complexity: Time → O(n) Space → O(1) 📚 What I Learned: Bit-level thinking can simplify problems that look complex with normal counting 💬 Question for You: Can you solve this problem using XOR without counting bits? 🤔 #DSA #Java #Coding #ProblemSolving #InterviewPrep #LeetCode #TechJourney #142DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Every Day – Day 2 📍 Problem: Minimum Distance to Target Element 💡 Platform: LeetCode 🧠 Approach: Brute Force with Bidirectional Traversal 🔍 Problem Summary: Given an array, a target value, and a starting index, find the minimum distance between the start index and any index where the target exists. ⚙️ Approach Explained: Traverse forward (start → end) Traverse backward (start → beginning) For each occurrence of target: Compute distance → |start - i| Maintain the minimum distance 📈 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 🎯 Key Takeaways: Always think in terms of distance minimization problems Bidirectional traversal ensures complete coverage Can be optimized further using early stopping if needed Tell me your approach in comments ? Would love if people would like to join me in this habit for learning every day. 🔥 Progress: Day 2/ 60 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #SoftwareEngineering #60DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 25 of My DSA Journey Solved LeetCode Problem #2089 – Find Target Indices After Sorting Array today! 🔍 This problem focuses on understanding how sorting impacts element positions and how we can determine indices efficiently without actually modifying the array. 💡 Key Learnings: Sorting changes element positions, but relative counts help track indices Instead of sorting, we can count: Elements less than target Elements equal to target This approach avoids unnecessary sorting and improves efficiency 🧠 Approach: Count how many elements are smaller than target → gives starting index Count how many elements are equal to target → determines range Generate indices from start to start + count - 1 💻 Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) Consistency is the real game changer 💯 Day 25 completed — moving forward stronger 🚀 #Day25 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
Day 84 of My DSA Journey Today’s problem: Counting Bits Given a number n, the task is to return an array where each index i contains the number of 1’s in the binary representation of i. 🔍 Example: Input: n = 5 Output: [0, 1, 1, 2, 1, 2] 💡 Key Insight: Instead of counting bits every time, we reuse previous results: i >> 1 → removes last bit i & 1 → checks if last bit is 1 So, 👉 ans[i] = ans[i >> 1] + (i & 1) ⚡ This reduces time complexity to O(n) (single pass!) 📈 What I learned today: Dynamic Programming can simplify repeated computations Bit manipulation makes problems faster and cleaner Small patterns can lead to big optimizations #Day84 #DSA #Java #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 61 of My DSA Journey Today I solved LeetCode 436 – Find Right Interval on . 📌 Problem For each interval, find the minimum index of another interval whose start is greater than or equal to the current interval’s end. If no such interval exists → return "-1". --- 🧠 Approach – Sorting + Binary Search Steps I followed: • Created a separate array "starts[][]": - Stored "{start value, original index}" • Sorted this array based on start values • For each interval: - Applied Binary Search to find the smallest start ≥ current end - Stored the corresponding original index 👉 If no valid interval found → store "-1" --- ⏱ Time Complexity: "O(n log n)" • Sorting → "O(n log n)" • Binary search for each interval → "O(log n)" 📦 Space Complexity: "O(n)" — For storing start-index pairs --- 💡 Key Learnings ✔ Combining Sorting + Binary Search ✔ Preserving original indices after sorting ✔ Efficiently solving interval-based problems 👉 This problem is a great example of how preprocessing (sorting) simplifies complex searching 🚀 --- Consistency continues — getting stronger with every concept 💪🔥 #100DaysOfCode #DSA #BinarySearch #Sorting #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA Journey Update: 7/75 Solved another problem today: Product of Array Except Self 💡 Key Idea: Used prefix (left) and suffix (right) products to build the answer without using division and in O(n) time. 🔍 Example: Input: [1,2,3,4] Output: [24,12,8,6] ⚡ Learning: Optimized approach using two passes Space optimization by reusing the same array Stronger understanding of prefix/suffix patterns Step by step progress… consistency matters more than speed 🔥 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 22/100 — LeetCode Today’s problem: Happy Number 😊 At first, it looked like a simple math problem… but it turned out to be about patterns and repetition. 🔍 What I learned: Break a number into digits using % 10 and / 10 Square each digit and keep adding Repeat the process until: You reach 1 → Happy Number ✅ Or it starts repeating → Not Happy ❌ 🧠 Key Insight: This problem is actually about cycle detection — if a number repeats, it will never reach 1. ⚡ Simple Example: 19 → 82 → 68 → 100 → 1 ✅ 💡 Takeaway: Sometimes problems that look like math are really about loops and patterns. Small steps every day → Big improvement 🚀 #Day22 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 13 of 180 — 3Sum ✅ Today I did the 3Sum problem. How I did it? 1. Using the two pointer technique. 2. Ran a for loop from i = 0 to n - 2, where n = array length. Checked two things: 3. If current element > 0 → not possible to get a valid answer, so break. 4. Avoid same ith number by comparing it with the previous value. If previous value is same as current value, move to next ith element. Initialized pointers: left = i + 1 right = n - 1 5. Found sum: If it is 0 → added triplet to list 6. Checked for duplicates: If left points to same second number → move left If right points to same third number → move right 7. If sum < 0 → left++ to increase sum 8. If sum > 0 → right-- to decrease sum 9. At last, returned the list. Day 13 done. 167 to go. 🔥 #180DaysDSA #Day12 #LeetCode #Java #DSA #TwoPointers #Strings #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
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