LeetCode Challenge – Day 46 Today I solved the Search in Rotated Sorted Array problem. Problem Insight: We are given a sorted array that has been rotated at some unknown index. The task is to find the index of a target element in O(log n) time. Approach: Applied Binary Search At every step, identified which half of the array is sorted Checked whether the target lies in the sorted half Narrowed down the search space accordingly Key Learning: Even if the array is not fully sorted, one half is always sorted. Using this observation, we can still apply binary search efficiently. Complexity: Time: O(log n) Space: O(1) Initially, this problem felt confusing, but breaking it into smaller decisions made it much easier to understand. #LeetCode #Java #DSA #CodingJourney
LeetCode Challenge - Search in Rotated Sorted Array
More Relevant Posts
-
LeetCode Challenge – Day 49 Today I solved the Linked List Cycle problem. Problem Insight: Given a linked list, determine whether it contains a cycle (loop). A cycle occurs when a node points back to a previous node instead of reaching null. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare) Maintained two pointers: Slow pointer moves one step at a time Fast pointer moves two steps at a time If a cycle exists, both pointers will eventually meet If not, the fast pointer will reach the end of the list Key Learning: Using two pointers with different speeds helps efficiently detect cycles without extra space. Complexity: Time: O(n) Space: O(1) Understanding pointer movement made this problem much easier to solve. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🚀 Day 14 of LeetCode Problem Solving Solved today’s problem — LeetCode #34: Find First and Last Position of Element in Sorted Array 💻🔥 ✅ Approach: Binary Search (Twice) ⚡ Time Complexity: O(log n) 📊 Space Complexity: O(1) The task was to find the starting and ending position of a target element in a sorted array. 👉 Instead of linear search, I used Binary Search twice: One to find the first occurrence One to find the last occurrence 💡 Key Idea: Modify binary search slightly to keep searching even after finding the target. 👉 Core Logic: If target found → store index Continue searching left (for first position) Continue searching right (for last position) 💡 Key Learning: Binary Search is not just for finding elements — it can be modified to solve many variations efficiently. Consistency is the key — getting better every day 🚀 #Day14 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 89 / 100 – LeetCode Challenge Today’s problem: Symmetric Tree (Easy) 🌳 👉 Problem: Check whether a binary tree is a mirror of itself (symmetric around its center). 💡 Key Insight: A tree is symmetric if the left and right subtrees are mirror images. That means: Left.left == Right.right Left.right == Right.left 🧠 Approach (Recursive): If both nodes are null → symmetric ✅ If only one is null → not symmetric ❌ If values match → recursively check cross children ⏱ Complexity: Time: O(n) Space: O(h) 🔥 Takeaway: This problem teaches how to think in terms of mirror recursion instead of normal traversal. #Day89 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #BinaryTree #Recursion
To view or add a comment, sign in
-
-
🚀 Day 88 / 100 — LeetCode Challenge Solved: Find Minimum in Rotated Sorted Array 💡 Approach: Used Binary Search (O(log n)) to efficiently locate the minimum element in a rotated sorted array. Instead of scanning linearly, compared mid with high to decide the search direction. 🔍 Key Insight: If nums[mid] > nums[high] → minimum is in the right half Else → minimum is in the left half (including mid) ⚡ Performance: Runtime: 0 ms (Beats 100%) Memory: 43.92 MB 🧠 Learning: Understanding how sorted + rotated arrays behave helps reduce time complexity drastically from O(n) → O(log n) Consistency is key. 12 days to go 💯🔥 #Day88 #LeetCode #BinarySearch #Java #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 4 of My LeetCode Journey Solved today’s POTD (Problem of The Day): Closest Equal Element Queries (Medium) 📝 Problem Summary Given a circular array, for each query index, find the minimum distance to another index having the same value. If no such index exists, return -1. 🧠 Intuition Instead of checking every index for each query (brute force), I realized we only need to focus on positions where the same value occurs. 💡 Approach ✔️ Used a HashMap to store: value → list of indices ✔️ For each query: Found the index position using binary search Checked only left and right neighbors (closest possible matches) ✔️ Calculated distance using circular logic: min(|i - j|, n - |i - j|) 📚 Key Learning Smart preprocessing can reduce time complexity significantly In circular arrays, always consider wrap-around distance Nearest element problems often reduce to adjacent comparisons #LeetCode #Day4 #DSA #ProblemOfTheDay #Java #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 87 — LeetCode Practice 🚀 Today’s focus was on ranking logic and nested iteration concepts. ✅ Problem solved today: 🔹 Relative Ranks 💡 Key learnings from today: • Understood how to determine ranks by comparing each element with others • Learned how counting higher scores helps assign positions • Strengthened concepts of nested loops and conditional logic • Explored how to map rankings into strings like Gold Medal, Silver Medal, Bronze Medal • Improved thinking on converting numeric logic into meaningful output 🧠 Approach used: Used a brute-force method where for each score, I counted how many scores are greater than it to determine its rank. ⚡ Time Complexity: O(n²) 📦 Space Complexity: O(n) 📈 Progress: Staying consistent and improving problem-solving step by step! #Day87 #LeetCode #DSA #Java #CodingJourney #Consistency #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Progress – Rotate Array Kicking off today’s DSA practice, I solved the “Rotate Array” problem on LeetCode. 🔍 Problem Overview: Given an integer array, rotate the array to the right by k steps, where k is non-negative. The rotation must be done in-place without using extra space. 💡 My Approach: Used the array reversal technique for optimal performance First reversed the initial part, then the remaining part, and finally the entire array Applied k = k % n to handle cases where k is greater than array size 📈 Key Takeaway: This problem reinforced my understanding of in-place array manipulation and how clever use of reversal algorithms can optimize both time and space complexity. Consistency is building confidence step by step 💯 #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #Learning
To view or add a comment, sign in
-
-
Day 56 : Crushing Binary Trees on LeetCode 💡 Today’s live practical session in Alpha Plus 7.0 We focused on some of the most challenging Binary Tree questions on LeetCode, breaking down the logic behind them. What I practiced today: ✅ Tree Diameter: understand the logic to calculate the absolute longest path between any two nodes in the entire tree. ✅ Maximum Path Sum: Tackled a famous "Hard" level problem! Figured out how to find the path with the highest possible sum, even if it doesn't pass through the root. ✅ Target Deletion: Wrote the recursive code to systematically find and delete leaf nodes that match a specific target value. #BinaryTree #LeetCode #ProblemSolving #DSA #Java #SoftwareEngineering #100DaysOfCode #ApnaCollege
To view or add a comment, sign in
-
-
Day 31 of #50DaysLeetCode Challenge 💻🔥 Today I solved the “Permutations” problem using Java. 🔹 Problem: Given an array of distinct integers, return all possible permutations. 🔹 Reality check: If you don’t understand recursion properly, this problem will expose you. There’s no shortcut here. 🔹 Approach (Backtracking): Fix one element at a time Swap it with every possible choice Recurse for the remaining positions Backtrack (undo the swap) to explore other possibilities 🔹 Key Insight: This isn’t about generating values — it’s about exploring a decision tree. Every level = a position in the array Every branch = a choice 🔹 Time Complexity: O(n!) — and that’s unavoidable 📌 What I learned: Backtracking is not optional for DSA. If you try to avoid it, you’ll get stuck on a whole category of problems. Stop memorizing patterns blindly. Understand why the recursion works. #Day25 #LeetCode #Java #Backtracking #DSA #CodingChallenge #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
-
Explore related topics
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