Day 2/100: Mastering the Pivot 🔄 Today’s challenge was LeetCode 33: Search in Rotated Sorted Array. The trick here isn't just finding the target—it’s identifying which half of the array is still sorted. Standard Binary Search assumes a perfect slope, but with a rotation, you have to find the "steady ground" before making your move. Constraint: O(\log n) runtime. Key Lesson: Even when data is disrupted (rotated), there is usually a sub-pattern you can exploit to maintain efficiency. One step closer to the goal! 🚀 #100DaysOfCode #Java #DataStructures #Algorithms #LeetCode
Mastering LeetCode 33: Search in Rotated Sorted Array
More Relevant Posts
-
Day 36/50 🚀 Solved “Valid Parentheses” today — a classic stack problem, but a great reminder that simple concepts can be powerful when applied correctly. 💡 Key takeaway: Using a stack makes it easy to track opening brackets and validate matching pairs efficiently. Every closing bracket should correspond to the most recent unmatched opening one — LIFO in action. ⚙️ What I focused on: Clean conditional checks Avoiding unnecessary complexity Writing readable, structured code 📈 Result: Accepted ✅ Optimized runtime & solid performance On to Day 37 🔥 #50DaysOfCode #DataStructures #Algorithms #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 3/100 – LeetCode Challenge 🔍 Problem: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be inserted to maintain the sorted order. 💡 Key Concepts Used: • Binary Search • Time Complexity Optimization – O(log n) • Efficient searching in sorted arrays 📚 What I Learned: • How binary search reduces search time significantly compared to linear search • Handling edge cases when the target element is not present • Determining the correct insertion index while maintaining sorted order hashtag #100DaysOfCode #LeetCode #Java #DataStructures #Algorithms #BinarySearch #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 103: Simple & Clean 🎯 Problem 1848: Minimum Distance to the Target Element After some complex DP challenges, today was a straightforward exercise in linear search and distance calculation. The Strategy: • Linear Traversal: I iterated through the array to find every occurrence of the target element. • Absolute Minimization: For each match, I calculated the absolute difference between the current index and the start index, keeping track of the minimum value found. Sometimes a simple, O(N) solution is all you need. Day 103 down—maintaining the streak with clarity and consistency. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
🚀 Day 571 of #750DaysOfCode 🚀 🔍 Problem Solved: Sum of Distances Today’s problem looked like a classic brute-force trap 👀 At first glance, comparing every pair gives an O(n²) solution — but with constraints up to 10⁵, that’s not going to work. 💡 Key Insight: Instead of comparing all pairs, we can: 👉 Group indices of the same value 👉 Use prefix sums to efficiently calculate distances 🧠 Approach: Group indices by value (using HashMap) For each group: Build prefix sum of indices For each index: Left contribution → i * count - sum Right contribution → sum - i * count Combine both to get final result 📈 Complexity: Time: O(n) Space: O(n) ✨ Takeaway: When you see distance-based problems: 👉 Think in terms of contributions instead of pair comparisons 👉 Prefix sums can turn expensive computations into linear time Another strong pattern added to the toolkit 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #PrefixSum #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
Worked on a challenging problem: “Subarrays with K Different Integers” Key takeaway: Instead of directly solving for exactly K distinct elements, I learned a smarter approach: 👉 count(at most K) − count(at most K−1) 🔹 Concepts I practiced: Sliding Window technique HashMap for frequency tracking Two-pointer approach 🔹 What stood out: The idea of counting all valid subarrays ending at each index using (r - l + 1) was really powerful. It completely changed how I think about subarray problems. Always learning, one problem at a time. #DataStructures #Algorithms #Java #LeetCode #SlidingWindow #LearningJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode Today’s problem focused on finding the minimum distance between a target element and a given index in an array. I solved it using a simple and efficient approach: Traversed the array once Checked for target occurrences Calculated distance using absolute difference Maintained the minimum value throughout Runtime: 0 ms (Beats 100%) Optimized space usage Key takeaway: Even straightforward iteration can lead to highly optimized solutions when combined with the right logic. #LeetCode #Java #DataStructures #Algorithms #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
60-Day LeetCode Challenge – Day 43 Solved Check If Two String Arrays are Equivalent on LeetCode. 📌 Approach: Concatenated both string arrays into two strings and compared them using .equals(). 🧠 Learning: Reinforced how string building and comparison works, especially when data is split across arrays. ⚡ Complexity: • Time Complexity: O(n + m) • Space Complexity: O(n + m) Simple logic, but a clean reminder that breaking a problem down makes it easier to solve. #LeetCode #DSA #Java #Strings #Consistency #ProblemSolving #LeetCode60
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode Solved LeetCode 179 – Largest Number 🔢 Today’s problem was a great reminder that sorting isn’t always straightforward. Instead of normal numeric sorting, the trick is to compare numbers based on their string concatenation order. 💡 Key Insight: To decide order between two numbers a and b, compare: ab vs ba Whichever forms the larger number should come first. 🔍 What I learned: Custom sorting using comparators Converting integers to strings for flexible comparison Edge case handling (like leading zeros → return "0") ⚡ Approach: Convert integers to strings Sort using (b+a).compareTo(a+b) logic Build the final result using StringBuilder 💻 Efficient and clean solution with strong real-world relevance in greedy + sorting problems #100DaysOfCode #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #DSAwithEdSlash @edslash
To view or add a comment, sign in
-
-
🚀 Day 63 of #100DaysOfLeetCode ✅ Problem Solved: Unique Binary Search Trees (LeetCode 96) Today’s problem was a great example of how Dynamic Programming and mathematical patterns (Catalan Numbers) come together. 🔍 Key Insight: For every node chosen as root, the number of unique BSTs is: 👉 Left Subtrees × Right Subtrees This leads to the recurrence: dp[n] = Σ (dp[left] × dp[right]) 💡 What I learned: Breaking problems into smaller subproblems makes complex structures easier Recognizing patterns like Catalan Numbers is a game changer DP is not just about arrays, it's about thinking smart ⚡ Result: ✔️ Runtime: 0 ms (Beats 100%) ✔️ Clean and optimized solution Consistency is slowly turning into confidence 💪 #LeetCode #DataStructures #DynamicProgramming #CodingJourney #ProblemSolving #Java #100DaysOfCode
To view or add a comment, sign in
-
-
I just solved LeetCode 662: Maximum Width of Binary Tree! Finding the width is different from a normal traversal because you have to account for the empty spaces between nodes. I used a simple indexing trick ($2i+1$ and $2i+2$) and an ArrayDeque to track positions. By using peekFirst() and peekLast(), I could instantly calculate the width of each level ($right - left + 1$). It’s a great example of how choosing the right data structure makes the logic much cleaner! #LeetCode #Java #BinaryTree #Coding
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