Day 39 | LeetCode Learning Journal 🚀 Today I solved Sqrt(x) using Binary Search. This problem helped me understand how searching techniques can be applied beyond arrays to mathematical problems! 🔑 Key Points: • Find the integer square root of a number. • Avoid using built-in sqrt functions. • Applied Binary Search to reduce time complexity. • Stored the last valid answer (floor value). 🌱 What I Learned: • How Binary Search can be used on answer space. • Importance of avoiding overflow using long long. • Efficient way to handle large inputs. • Strengthened problem-solving with math + logic. #LeetCode #100DaysOfCode #DSA #CodingJourney #Day39 🚀
Solving Sqrt(x) with Binary Search on LeetCode
More Relevant Posts
-
-- LeetCode 396 — Rotate Function This problem looks like a rotation problem… but it’s actually a math + observation problem. At first, the obvious approach is: 🔁 Rotate the array → recompute F(k) every time → O(n²) But that’s inefficient. -- The breakthrough moment: Instead of recomputing, track how the value changes after each rotation. We get: F(k) = F(k−1) + sum − n × nums[n−k] That’s it. One formula → transforms the solution to O(n) ⚡ 🧠 What clicked for me: Rotation problems often hide a pattern If you’re recalculating everything, you’re probably missing something Reusing previous computation is the real optimization #LeetCode #DSA #Algorithms #Coding #ProblemSolving #algorithm
To view or add a comment, sign in
-
-
🚀 Solved: Split Array Largest Sum (LeetCode 410) Today I worked on an interesting problem that combines Binary Search + Greedy approach. 💡 Problem Summary: Given an array and a number k, split the array into k subarrays such that the maximum sum among them is minimized. 🧠 Key Learning: Instead of brute force, we can: Apply Binary Search on the answer space Use a Greedy check function to validate splits 🔍 Core Idea: Lower bound = max element Upper bound = sum of array Minimize the largest subarray sum 📈 Time Complexity: O(n log(sum)) ✨ Problems like this really strengthen problem-solving skills around: Search space optimization Greedy decisions #LeetCode #DSA #BinarySearch #Coding #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 LeetCode 378 — Kth Smallest Element in a Sorted Matrix | Solved ✅ Solved this interesting problem using Binary Search on Answer — a powerful pattern! 🔍 Problem Insight: Matrix is sorted row-wise and column-wise, but not flattened. 💡 Approach: • Applied binary search on value range • For each mid, counted elements ≤ mid using matrix properties ⚡ Time Complexity: O(n × log(max - min)) ✨ Key Learning: Not all binary search problems are about indices — sometimes we search in the answer space. 📈 Result: Accepted ✔️ From searching positions → to searching values That’s where problem-solving evolves 🔥 Grateful to Pratyush Narain for the guidance and clear explanations. #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 35 | 100 Days of Coding Challenge #DrGViswanathanChallenge 📘 Problem Solved: Next Greater Element I (LeetCode) 🔧 Approach Used (Brute Force): • For each element in nums1, found its index in nums2 • Traversed to the right to find the first greater element • If none found, returned -1 📌 Key Idea: For every element, scan right side to find the next greater value. ⏳ Complexity: Time: O(n × m) Space: O(1) (excluding output) 🧠 Key Learning: Brute force helps build intuition, but this problem can be optimized using a monotonic stack for O(n) performance. 💡 Optimization Insight: Use a stack + hashmap to precompute next greater elements efficiently. 📂 Topics Covered: Arrays, Brute Force, Monotonic Stack #100DaysOfCode #DSA #CPP #LeetCode #CodingJourney #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Staying consistent and improving problem-solving skills with each step. LeetCode Progress 15/50 — Missing Number I worked on a problem focused on arrays and mathematical optimization 🧩 💡 The challenge was to find the missing number in a given range from 0 to n using an efficient approach. 🧠 Approach: Applied the sum formula of the first n natural numbers and compared it with the actual sum of the array to identify the missing value. This avoids the need for extra space and keeps the solution efficient. ⏱ Time Complexity: O(n) 💡 What I learned: This problem highlighted how mathematical concepts can simplify problems and lead to clean and optimized solutions. 📈 Strengthening fundamentals and exploring different ways to approach the same problem efficiently. #LeetCode #DSA #ProblemSolving #Cpp #CodingJourney 🚀
To view or add a comment, sign in
-
-
LeetCode #51 — N-Queens | Backtracking at Its Best Just solved the classic N-Queens problem — one of the most interesting backtracking challenges that tests logic, recursion, and optimization. Problem Insight:Place n queens on an n × n chessboard so that no two queens attack each other. That means: No same row No same column No same diagonal Approach: Backtracking + Safe Position Checks Place one queen row by row Check if the current position is safe If valid, move to the next row If stuck, backtrack and try another position What I Learned: 1) Backtracking is about trying possibilities efficiently 2) Constraints help prune unnecessary paths 3) Visualizing the board makes recursion easier to understand This problem is a great reminder that patience + recursion can solve even the toughest puzzles. #LeetCode #NQueens #Backtracking #Algorithms #CodingJourney #ProblemSolving #DSA #TechLearning
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
-
-
LeetCode Progress 39/50 — Binary Search Today I worked on a fundamental problem focused on searching and algorithmic efficiency 🧩 💡 The challenge was to locate a target element in a sorted array using an optimized approach. 🧠 Approach: Used binary search to repeatedly divide the search space in half, reducing comparisons and efficiently locating the target element. ⏱ Time Complexity: O(log n) 💡 What I learned: This problem reinforced how powerful divide-and-conquer techniques like binary search can be for improving performance. 📈 Strengthening understanding of fundamental algorithms and improving efficiency in problem-solving. #LeetCode #DSA #BinarySearch #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Day 43 of My DSA Journey 🔍 LeetCode Problem #153 – Find Minimum in Rotated Sorted Array Today’s problem was a great application of Binary Search with a twist. Instead of searching for an element, the goal was to find the minimum in a rotated sorted array while maintaining O(log n) complexity. 💡 Key Learning: By comparing the middle element with the right boundary, we can determine which part of the array contains the minimum. ⚡ Insight: If the middle element is greater than the rightmost element, the minimum lies in the right half; otherwise, it lies in the left half. 📌 Takeaway: Binary Search is not just about finding elements — it can also be used to identify patterns and optimize search space efficiently. Consistency continues — Day 43 💪 #Day43 #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 206 Problem: Longest Univalue Path 🌳📏 Today’s problem is a beautiful example of Tree DFS + Path Aggregation. 🧠 Problem Summary You are given: 👉 A binary tree 🎯 Goal: Find the length of the longest path where: ✅ All nodes in the path have the same value ✅ Path can be anywhere (not necessarily through root) ✅ Length is measured in edges, not nodes 💡 Key Insight At every node, we try to: 👉 Extend paths from left and right only if values match 🔥 Important observation: A valid path can: ➡️ Go left → node → right (through current node) ➡️ Or extend only in one direction ⚙️ Approach (DFS) 1️⃣ Perform DFS on tree 2️⃣ For each node: Get longest path from left subtree Get longest path from right subtree 3️⃣ Check value match: If left child has same value → extend path If right child has same value → extend path 4️⃣ Update global result: 👉 left_path + right_path (This forms a path passing through current node) 5️⃣ Return to parent: 👉 Only one side (max of left/right), since path must be continuous 📈 Complexity Time Complexity: O(n) Space Complexity: O(h) (recursion stack) ✨ Why This Problem Is Important This problem teaches a powerful tree pattern: 🔥 Return something to parent, update global answer locally 💡 Key Learnings: ➡️ Tree problems often need two perspectives: What to return upward What to compute globally ➡️ Not every path goes through root ➡️ Combine left + right for best answer This pattern appears in: ➡️ Diameter of Binary Tree ➡️ Maximum Path Sum ➡️ Longest ZigZag Path 🔖 #DSA #100DaysOfCode #Day206 #Trees #DFS #BinaryTree #LeetCode #Algorithms #ProblemSolving #CodingChallenge #InterviewPrep #Python #SoftwareEngineering #DeveloperJourney #TechCommunity #CodingLife
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