Day 12/100 – Building Consistency in DSA Solved “Sqrt(x)” (LeetCode #69) today using a Binary Search approach. The challenge was to compute the square root of a non-negative integer without using built-in functions, while ensuring the result is rounded down. What stood out: This problem highlights how Binary Search can be applied beyond sorted arrays—specifically in narrowing down an answer space efficiently. Key Insights: Reduced time complexity from O(n) to O(log n) Strengthened understanding of boundary conditions and edge cases Practiced writing precise and overflow-safe logic Takeaway: Problems labeled “Easy” often carry fundamental patterns that are crucial for solving harder problems. Consistency > Intensity. Showing up every day. #Day12 #100DaysOfCode #DSA #LeetCode #BinarySearch #ProblemSolving #SoftwareEngineering
Binary Search Solves LeetCode #69 Sqrt(x)
More Relevant Posts
-
Solved: Find Peak Element (LeetCode) I recently worked on the “Find Peak Element” problem and implemented an efficient solution using Binary Search. • Runtime: 0 ms (Beats 100%) • Approach: Binary Search • Time Complexity: O(log n) *Approach Summary:- Instead of using a linear scan, I applied binary search to reduce the search space: • If the middle element is smaller than the next element, the peak lies on the right side • Otherwise, the peak lies on the left side • Continue narrowing down until a peak element is found. *Key Takeaways:- • Binary search can be applied beyond sorted arrays • Optimizing from O(n) to O(log n) makes a significant difference • Careful handling of boundary conditions is important Consistently practicing problems like these is helping me strengthen my problem-solving skills and understanding of algorithms. #LeetCode #DSA #BinarySearch #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 7 of My LeetCode Journey Today’s problem: Search in Rotated Sorted Array At first glance, it looks like a normal search problem… but the rotation makes it interesting 🤯 💡 Key Insight: Used Binary Search by identifying which half of the array is sorted at each step. This helps decide where to continue the search efficiently. ⚡ Optimized Approach: Check which half is sorted Decide if target lies in that half Narrow down search space ⏱️ Time Complexity: O(log n) ⚡ Performance: 0 ms (Beats 100%) 🧠 What I Learned: Binary Search is all about pattern recognition Even “unsorted-looking” arrays can have structure Thinking logically > brute force #LeetCode #DSA #CodingJourney #BinarySearch #ProblemSolving
To view or add a comment, sign in
-
-
Day 1 of DSA🚀 Solved "Maximum Depth of Binary Tree" on LeetCode 🌳 Approach I used: Step 1: If the node is null, return 0 (base case) Step 2: Recursively find depth of left subtree Step 3: Recursively find depth of right subtree Step 4: Take max of left and right depth and add 1 This gives the maximum depth (longest path from root to leaf). Simple recursion, but very useful for understanding tree problems. Consistency is more important than perfection 🔥 #LeetCode #DSA #BinaryTree #Recursion #CodeHelp
To view or add a comment, sign in
-
-
🚀 Day 54 of My DSA Journey Solved LeetCode Problem #275 – H-Index II Today’s problem focused on Binary Search and understanding how sorted data can help optimize solutions from linear time to logarithmic time. 🔍 Problem Insight: Given a sorted citations array, the goal was to find the maximum h such that at least h papers have h or more citations. 💡 Key Learning: Instead of checking every possible value, Binary Search helps efficiently identify the correct h-index in O(log n) time. ⚡ Main Observation: At any index i, the number of papers with at least citations[i] citations is n - i. This relationship makes Binary Search possible. 📌 Takeaway: Whenever the input is sorted, always think about Binary Search before using brute force. It can drastically improve performance. Consistency continues 💪 #Day54 #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #Cpp
To view or add a comment, sign in
-
-
🚀 Day 42 of #LeetCode75 Problem: Reorder Routes to Make All Paths Lead to City 0 Today’s problem looked tricky at first, but the moment I understood the graph intuition, it became elegant 🔥 💡 Key Insight: We convert the directed graph into an undirected one while tracking edge directions. Original direction → needs change (cost = 1) Reverse direction → already correct (cost = 0) Then simply run DFS/BFS from node 0 and count how many edges need reversal. 🧠 What I Learned: How to handle direction in graphs using smart encoding Importance of transforming problems into simpler representations Strengthened my DFS concepts ⏱ Complexity: Time: O(n) Space: O(n) Problems like these remind me that clarity > complexity 📈 Consistency is the key — showing up every day! #Day45 #LeetCode #DSA #CodingJourney #SoftwareEngineer #GraphTheory #DFS #BFS #ProblemSolving #CodingDaily #TechJourney #LearningInPublic
To view or add a comment, sign in
-
-
📱 LeetCode 17 – Letter Combinations of a Phone Number | Mastering Backtracking Solved a classic recursion problem today that perfectly demonstrates the power of backtracking and combination building. The challenge: given a string of digits (2–9), generate all possible letter combinations based on the traditional phone keypad mapping. 💡 Key Insight: Each digit maps to multiple characters, and the goal is to explore all possible combinations by picking one character from each digit. This naturally leads to a backtracking approach, where: We build combinations step by step Explore all possibilities recursively Backtrack to try different paths ⚙️ Approach: Use a mapping of digits → letters Traverse the input using recursion Append characters and move forward Store the result when a valid combination is formed 🚀 Complexity: Time: O(4ⁿ) Space: O(n) (recursion stack) 📌 What I learned: How to think in terms of recursion trees Efficiently generating combinations Writing clean and structured backtracking code Problems like this build a strong foundation for tackling advanced topics like DFS, recursion, and combinatorial algorithms. #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🧩 Problem: Minimum Absolute Distance Between Mirror Pairs You are given an integer array nums. 🎯 Goal Find the minimum distance between indices i and j such that: One number is the mirror (reverse) of the other i.e., nums[i] == reverse(nums[j]) If no such pair exists, return -1. 🧠 Key Intuition A “mirror pair” means: Reverse the digits of a number Remove leading zeros after reversing Compare with another number Example: 120 → 021 → 21 Efficient idea: While iterating, store the index of reversed numbers For each number: Compute its mirror (reverse) Check if we've already seen its pair This avoids checking all pairs O(n²) 🛠 Approach 1️⃣ Traverse the array 2️⃣ For each number: Convert to string Reverse it Remove leading zeros Convert back to integer → rev 3️⃣ Check in map: If current number exists in map → update answer 4️⃣ Store: map[rev] = current index 5️⃣ Keep track of minimum distance 📈 Complexity Analysis Time Complexity: O(n × d) (d = number of digits) Space Complexity: O(n) 🔗 Problem https://lnkd.in/d_KcNEqb 💻 Solution https://lnkd.in/dvcVRvTu #LeetCode #Cpp #DSA #Algorithms #HashMap #Strings #ProblemSolving #CodingChallenge #LeetCodeDailyChallenge #CompetitiveProgramming #CodingJourney
To view or add a comment, sign in
-
Spent some time solving 3 really interesting LeetCode contest problems today, and each one reinforced a different core DSA pattern. What I enjoyed most was how these seemingly small problems were actually testing pattern recognition more than implementation. 1) Mirror Frequency Distance This problem was all about symmetry and frequency mapping. Approach That I Used: Count the frequency of each character in the string. Map each character to its mirror counterpart: a ↔ z, b ↔ y 0 ↔ 9, 1 ↔ 8 Iterate through only half the range to avoid double counting. Sum the absolute frequency differences for every mirror pair. 2) Integers With Multiple Sum of Two Cubes This one immediately reminded me of the Ramanujan number (1729) concept. Approach That I Used: Generate all valid cube pairs (a, b) where: a³ + b³ ≤ n Store the frequency of each generated sum in a hashmap. Any number appearing 2+ times has multiple distinct cube representations. Return all such integers in sorted order. 3) Minimum Increments to Maximize Special Indices The most interesting one of the three because it involved DP state compression. & it took me an hour to do this question Approach: Treat every valid index as a candidate peak. Compute the cost required to make it greater than both neighbors. Maintain two rolling states: choose current index as peak skip current index Optimize first for: maximum number of peaks minimum cost among those choices Biggest learning from today: Contest questions often look implementation-heavy, but the real skill lies in identifying the hidden reusable pattern: frequency symmetry pair generation DP The more patterns we recognize, the faster we grow as problem solvers. Consistency is the real game changer. #LeetCode #DSA #DynamicProgramming #CompetitiveProgramming #ProblemSolving #C++ #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 49 of My DSA Journey 🔍 LeetCode Problem #212 – Word Search II Today’s problem was a challenging combination of Trie (prefix tree) and backtracking. The goal was to find all words from a given list that can be formed in a 2D board by connecting adjacent letters. 💡 Key Learning: Using Trie helps optimize the search by pruning unnecessary paths early instead of checking each word separately. ⚡ Insight: Combining DFS with Trie significantly reduces time complexity compared to brute force approaches. 📌 Takeaway: Advanced data structures like Trie can make a huge difference when dealing with multiple string searches. Consistency continues — Day 49 💪 #Day49 #LeetCode #DSA #Trie #Backtracking #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 1: LeetCode - 35. Search Insert Position Starting my DSA journey with a classic binary search problem. Sometimes the goal isn’t just to find an element, but to figure out where it belongs. The Key Insight: If the target is not present, the correct insert position is exactly where the binary search ends — the low pointer naturally points to that position. My Approach: Apply binary search on the sorted array Compare mid with target and adjust search space If not found, return low as the insert index Takeaway: Binary search is more than searching — it helps solve positioning problems efficiently. Time Complexity: O(log N) | Space Complexity: O(1) Day 1 completed. #DSA #BinarySearch #LeetCode #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