Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
LeetCode 540: Single Element in Sorted Array with Binary Search
More Relevant Posts
-
Day 15 of Daily DSA 🚀 Solved LeetCode 162: Find Peak Element ✅ Approach: Used Binary Search to efficiently find a peak element. At each step, compared the middle element with its neighbors to decide which side must contain a peak. This works because at least one peak always exists in the array. ⏱ Complexity: • Time: O(log n) — binary search on array • Space: O(1) — no extra space used 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.20 MB (Beats 75.11%) A great example of how binary search can be applied beyond just sorted arrays. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 97 of #100DaysOfCode Solved LeetCode #1022 – Sum of Root To Leaf Binary Numbers ✅ A neat blend of DFS traversal and binary math, turning root-to-leaf paths into numbers. Key Takeaways: -> DFS with an accumulated binary value -> Using left shift (num * 2) to build numbers efficiently -> Correctly identifying leaf nodes for the final sum -> Simple recursion, strong fundamentals 🌳➡️🔢 Language: Java -> Runtime: 0 ms (Beats 100%) ⚡ -> Memory: 43.76 MB Consistency wins. Almost at the finish line 💻🔥 #LeetCode #Java #BinaryTree #DFS #Recursion #BitManipulation #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 29 of Daily DSA 🚀 Solved LeetCode 287: Find the Duplicate Number ✅ Problem: Given an array containing n + 1 integers where each number is in the range [1, n], find the duplicate number. Approach: Used the index marking technique. Key Idea: Treat the value as an index Convert the value to absolute (Math.abs) Mark the visited index by making the number negative If we encounter an index that is already negative, that value is the duplicate This allows us to detect duplicates efficiently without extra space. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 4 ms (Beats 91.67%) ⚡ • Memory: 82.75 MB A clever trick that uses the array itself as a visited map. #DSA #LeetCode #Java #ProblemSolving #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 22 - Find First and Last Position of Element in Sorted Array Technique Used: Modified Binary Search (Lower Bound & Upper Bound) Key Idea: Implemented two separate binary searches: One to find the first occurrence of the target, One to find the last occurrence Maintained an answer variable and continued searching left/right even after finding the target to determine boundaries. Time Complexity: O(log n) #Day22 #LeetCode #Java #BinarySearch #DSA #Algorithms
To view or add a comment, sign in
-
-
🎯 Day 100 of #100DaysOfCode 🔥 What a way to wrap it up! Solved LeetCode #3666 – Minimum Operations to Equalize Binary String ✅ A problem that blends math, parity logic, and careful case analysis—not your usual binary flip question. Key takeaways: -> Count-based optimization over brute force -> Handling even/odd operation patterns smartly -> Early exits = cleaner & faster logic -> Thinking in terms of operations feasibility rather than simulation 🧠 Language: Java -> Runtime: 0 ms (Beats 83.87%) -> Memory: 47.90 MB 100 days. Countless problems. One habit built: consistency 💪 Onward to harder problems and deeper concepts 🚀 #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #Consistency #100DaysChallenge
To view or add a comment, sign in
-
-
🚀 Day 60 of DSA consistency Today I practiced a Binary Search Tree (BST) problem: Search in a Binary Search Tree. In this problem, we need to find a node with a given value in a BST and return the subtree rooted at that node. 🔹 Key Idea: A BST has the property: Left subtree values < root Right subtree values > root Using this property, we can efficiently search by moving left or right instead of traversing the entire tree. 📊 Complexity Analysis Time Complexity: O(h) → where h is the height of the BST Space Complexity: O(h) due to recursion stack If the tree is balanced, the complexity becomes O(log n). #DSA #Java #BinarySearchTree #CodingJourney #Consistency #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 29/75 — Search Insert Position Today's problem focused on applying binary search on a sorted array. Goal: Return the index of a target value if it exists. If it does not exist, return the index where it should be inserted. Approach: • Use binary search to locate the target • If the element is not found, the left pointer represents the correct insertion index Key idea: return left Because after binary search ends, left naturally points to the position where the target should be inserted. Time Complexity: O(log n) Space Complexity: O(1) 29/75 🚀 #Day29 #DSA #BinarySearch #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 85/100 – LeetCode Challenge ✅ Problem: #226 Invert Binary Tree Difficulty: Easy Language: Java Approach: Recursive DFS (Divide and Conquer) Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Swap left and right child at every node, then recursively invert both subtrees. Classic recursion problem — made famous by Google interview story. Solution Brief: Base case: if root is null, return null. Swap left and right children using temporary variable. Recursively call invertTree on left and right subtrees. Return the root (now inverted). #LeetCode #Day85 #100DaysOfCode #Tree #Java #Algorithm #CodingChallenge #ProblemSolving #InvertBinaryTree #EasyProblem #DFS #Recursion #DSA
To view or add a comment, sign in
-
-
Day 23 - Find Minimum in Rotated Sorted Array Technique Used: Modified Binary Search Key Idea: Since the array is rotated but originally sorted, used binary search to identify the pivot (minimum element). Compared mid with end to determine which half is unsorted and adjusted boundaries accordingly. Time Complexity: O(log n) #Day23 #LeetCode #Java #BinarySearch #DSA #Algorithms
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