🔍 Day 66 of #100DaysOfCode 🔍 🔹 Problem: Binary Search – LeetCode ✨ Approach: Implemented an iterative binary search to efficiently locate the target element within a sorted array. By halving the search range each time — adjusting low and high around the mid-point — the algorithm achieves blazing-fast lookups! ⚡ 📊 Complexity Analysis: Time Complexity: O(log n) — array size halves with each iteration Space Complexity: O(1) — constant extra space ✅ Runtime: 0 ms (Beats 100.00%) ✅ Memory: 46.02 MB 🔑 Key Insight: Binary Search is proof that efficiency isn’t about doing more — it’s about eliminating what’s unnecessary. 🚀 #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #BinarySearch #LogicBuilding #Efficiency #ProgrammingChallenge #CodeJourney #CodingDaily
Implemented Binary Search for #100DaysOfCode with O(log n) time complexity
More Relevant Posts
-
🔥 Day 222 - Daily DSA Challenge! 🔥 Problem: 🌳 Flatten Binary Tree to Linked List Given the root of a binary tree, flatten it into a linked list in-place, following the preorder traversal order (root → left → right). 💡 Key Insights: 🔹 The goal is to modify the tree without using extra space. 🔹 For each node, if a left subtree exists: 1️⃣ Find the rightmost node of the left subtree. 2️⃣ Connect that node’s right pointer to the current node’s right subtree. 3️⃣ Move the left subtree to the right and set left = null. 🔹 Repeat this process while traversing through the tree. ⚡ Optimized Plan: ✅ Traverse using a pointer (curr). ✅ If curr.left exists, attach it in place of curr.right and re-link the subtrees. ✅ Continue the process until the end of the tree. ✅ Time Complexity: O(n) — each node visited once. ✅ Space Complexity: O(1) — in-place transformation. 💬 Challenge for you: 1️⃣ Can you flatten the tree using recursion instead of iteration? 2️⃣ How would you modify this to produce a postorder or inorder flattened list? #DSA #BinaryTree #LinkedList #LeetCode #ProblemSolving #CodingChallenge #KeepCoding #100DaysOfCode
To view or add a comment, sign in
-
-
✨ Day 50 of 50 Days Challenge ✨ Solved LeetCode 154: Find Minimum in Rotated Sorted Array II (Hard) 👉 Problem Statement: Given a sorted array that has been rotated between 1 and n times and may contain duplicate elements, find the minimum element in the array. The goal is to minimize operations (preferably better than O(n)). 📌 Examples: Input: nums = [1,3,5] Output: 1 Input: nums = [2,2,2,0,1] Output: 0 🔎 Approach Used: ➡️ Modified Binary Search (Handles Duplicates) 1. Initialize two pointers — start and end. 2. If elements at start, mid, and end are equal, shrink the range (start++, end--). 3. If the left half is sorted, update minEle with nums[start] and move to the right. 4. Otherwise, update minEle with nums[mid] and move to the left. 5. Continue until the minimum element is found. ✅ Complexity Analysis: Time Complexity: O(log n) on average, can degrade to O(n) (due to duplicates). Space Complexity: O(1) → Constant extra space. #50DaysChallenge #LeetCode #C++ #BinarySearch #RotatedArray #Duplicates #DSA #CodingChallenge #Algorithms
To view or add a comment, sign in
-
-
🔥 Day 92 of My LeetCode Journey — Problem 28: Find the Index of the First Occurrence in a String 💡 Problem Insight: Today’s problem was about finding the first occurrence of a substring (needle) inside another string (haystack). Essentially, it’s like implementing your own version of the strStr() function — a classic problem in string searching. 🧠 Concept Highlight: This challenge sharpens understanding of string traversal and pattern matching. The intuitive solution uses simple iteration and substring comparison, while the optimized approach can involve algorithms like KMP (Knuth-Morris-Pratt) for efficient searching. 💪 Key Takeaway: Sometimes, even built-in functions hide deep logic beneath simplicity — mastering these fundamentals builds confidence for more advanced string algorithms. ⚙️ Daily Reflection: Every search begins with clarity — whether in code or in life. Precision and patience always lead to the right match. #Day92 #LeetCode #100DaysOfCode #StringSearch #PatternMatching #ProblemSolving #DSA #CodingJourney #LearnByDoing #SoftwareEngineering
To view or add a comment, sign in
-
-
🔗 Day 75 of #100DaysOfCode 🔗 🌳 Problem: Binary Tree Postorder Traversal – LeetCode ✨ Approach: Implemented a recursive depth-first traversal that processes the left subtree, then right subtree, and finally the root node — perfectly matching the postorder pattern (Left → Right → Root). The solution is clean, intuitive, and highlights the elegance of recursion in tree traversal! 🌿 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each node is visited exactly once 💾 Space Complexity: O(n) — recursion stack in the worst case (skewed tree) ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 43.07 MB 💡 Key Insight: Recursion beautifully mirrors the natural hierarchy of trees — by trusting the call stack, we achieve simplicity and clarity in solving even complex traversal problems. 🌱 #LeetCode #100DaysOfCode #ProblemSolving #DSA #BinaryTree #Recursion #AlgorithmDesign #CodeJourney #ProgrammingChallenge #LogicBuilding #Efficiency #CodingDaily
To view or add a comment, sign in
-
-
🌟 Day 84 of #100DaysOfCode 🌟 🔹 Problem Solved: Check If All 1's Are at Least K Places Away – LeetCode Today’s challenge was all about precision, pattern detection, and distance validation within a binary array. The goal? Ensure every 1 is properly spaced and respects the minimum distance k. ✨ Approach: I iterated through the array, tracked the position of each 1, and checked the gap before encountering the next one. A simple but effective two-pointer style logic! 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — single pass through the array 💾 Space Complexity: O(1) — constant extra memory 🚀 Performance: ✔ Runtime: 1 ms (Beats 99.71%) ✔ Memory: 65.68 MB 🔑 Key Insight: Even a straightforward problem can sharpen your ability to detect patterns and handle constraints efficiently. Small details—like distances between bits—can make or break logic. #LeetCode #DSA #CodingChallenge #100DaysOfCode #ProblemSolving #BinaryArray #Algorithms #TechJourney #CodeEveryday #JavaCoding
To view or add a comment, sign in
-
-
There are a bunch of hard problems on LeetCode that use basic graph traversal, which is pretty straightforward. However, they might be a bit more complex because we need to create, or identify how to create, a graph representation. The post: https://lnkd.in/dtQCR26x The problem: https://lnkd.in/dEfwjQPN #LeetCode #DSATips #DSA #ThinkDSA #ProblemSolving
To view or add a comment, sign in
-
-
#Day 24: #100DaysOfCodingChallenge 🔍✨ Back to fundamentals today with the classic Binary Search! Sometimes revisiting core algorithms reinforces why they're foundational—elegant, efficient, and essential for any programmer's toolkit. Every problem solved adds another brick 🧱 to the foundation! 🟢 LeetCode 704: Binary Search 🔹 Difficulty: Easy ⏱️ Time Complexity: O(log n) 💾 Space Complexity: O(1) 🕒 Time Taken: 0 ms 💡 Approach: Used two pointers (left and right) to define the search space. In each iteration, calculated mid and compared it with target—if equal, returned mid; otherwise, eliminated half the search space by updating pointers. The beauty lies in halving possibilities with each comparison!
To view or add a comment, sign in
-
-
🔹 Problem: Binary Tree Inorder Traversal Day 122 🔹 Difficulty: Easy 🔹 Topic: Binary Tree / Morris Traversal / Iterative Traversal 🔍 Problem Breakdown: We are given the root of a binary tree, and we need to return the inorder traversal of its nodes’ values. 📘 Inorder Traversal: Left → Root → Right Usually, this can be solved using recursion or stack, but today’s approach uses Morris Traversal, which is O(1) extra space and does not use recursion or stack. 🧠 Approach (Morris Traversal): Start with the current node = root. If the left child is NULL, visit the node and move right. Else, find the inorder predecessor (rightmost node in the left subtree). If predecessor’s right is NULL, make a temporary link to the current node and move left. If predecessor’s right is current, remove the link, visit current node, and move right. Continue until all nodes are visited. This method avoids recursion and stack by establishing temporary links in the tree. ⏱️ Time & Space Complexity: Time Complexity: O(n) — each edge is visited twice. Space Complexity: O(1) — no recursion or stack used. 💡 Key Insight: Morris Traversal is a brilliant way to traverse binary trees in constant space, by cleverly using tree links as temporary pointers — elegant and efficient! #LeetCode #DSA #BinaryTree #MorrisTraversal #InorderTraversal #ProblemSolving #CodingChallenge #200DaysOfCode #Cplusplus
To view or add a comment, sign in
-
-
🚀Day 77 of #120_Days_leetCode Challenge ! LeetCode Problem: Find and Replace Pattern Today’s problem was all about pattern matching with bijective mappings — where we find words that match a given pattern by establishing a one-to-one relationship between letters. 🧩 Problem Summary: Given a list of words and a string pattern, return all words that match the pattern. A word matches if you can permute letters such that each letter in the pattern maps uniquely to a letter in the word. 📘 Example: Input: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb" Output: ["mee","aqq"] 💡 Intuition: To verify a match, we need to ensure: Each character in the pattern maps to only one unique letter in the word. No two pattern characters map to the same word character. This makes it a bijection problem — a perfect use case for hash maps. 🧠 Key Takeaways: Used two hash maps to maintain bijective character mapping. Achieved O(n * k) time complexity, where n = number of words and k = word length. Great practice for mastering string and hashmap-based logic problems. ✨ Every such problem reinforces how powerful simple mapping logic can be when applied thoughtfully. #LeetCode #ProblemSolving #CodingChallenge #DataStructures #Algorithms #ProgrammingJourney
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