🚀 Day 8 of #100DaysOfCode Solved LeetCode Problem 69 – Sqrt(x) today using a simple loop approach! 🔍 Problem Summary: Given a non-negative integer "x", return the square root of "x" rounded down to the nearest integer (without using built-in functions). 💡 What I practiced: - Basic iteration using loops - Handling overflow using "long" - Understanding how brute force works before optimizing ⚡ Approach (Brute Force): Start from "i = 0" and keep checking: "i * i <= x" Stop when it exceeds "x", and return "i - 1" 💻 Java Code: public static int mySqrt(int x) { long i = 0; while (i * i <= x) { i++; } return (int)(i - 1); } 📌 Takeaway: Starting with a simple loop helps build clarity. Optimization (like Binary Search) can come next! #LeetCode #Java #100DaysOfCode #CodingJourney #BasicsFirst #ProblemSolving
Sqrt(x) Solution using Simple Loop Approach
More Relevant Posts
-
Day 96 - LeetCode Journey Solved LeetCode 901: Online Stock Span in Java ✅ This problem is all about recognizing the pattern and using the right data structure. Instead of checking previous prices one by one, I used a Monotonic Stack to efficiently calculate spans. Every element is pushed and popped at most once → super optimized 🔥 Key idea: Keep removing smaller or equal previous prices and accumulate their spans. Key takeaways: • Monotonic Stack concept (very important) • Avoiding nested loops using stack optimization • Efficient span calculation • Thinking in patterns, not brute force ✅ All test cases passed ⚡ O(n) time and O(n) space This is one of those problems that truly levels up your stack game 💯 #LeetCode #DSA #Java #Stack #MonotonicStack #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 17 of #100DaysOfCode Today I worked on Binary Search (LeetCode 704) — a classic and powerful algorithm every developer should master. What I learned: How binary search reduces time complexity to O(log n) Importance of working on sorted arrays How to efficiently divide the search space using start, end, and mid Writing clean and optimal Java code for real interview scenarios Key takeaway: Instead of checking every element (O(n)), binary search helps us eliminate half of the data in each step — making it super fast and efficient. Problems like these remind me that understanding the logic is more important than just coding the solution. Consistency is the goal, improvement is the result. #Day17 #100DaysOfCode #Java #DataStructures #Algorithms #BinarySearch #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
Day 90 - LeetCode Journey Solved LeetCode 2181: Merge Nodes in Between Zeros in Java ✅ This problem is all about smart traversal and building a new linked list on the go. I used a dummy node + running sum approach. As I traversed the list, I kept adding values until I hit a zero. Once a zero appeared, I created a new node with the accumulated sum and reset the sum for the next segment. Clean, intuitive, and efficient. Key takeaways: • Using dummy node to simplify list construction • Handling segments using running sum • Clean traversal without extra data structures • Strong understanding of linked list manipulation ✅ All test cases passed ⚡ O(n) time and O(1) extra space Problems like this improve your ability to think in segments and patterns 🔥 #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 3/50 💡 Approach: Two Pointer (In-Place) The straightforward way uses an extra array — but the problem specifically says no copying! So I used the Two Pointer technique to solve it in-place with a single pass. 🔍 Key Insight: → Use a 'left' pointer to track where the next non-zero element belongs → Traverse with 'right' pointer — place non-zeros at left, then increment → Fill remaining positions with 0s at the end 📈 Complexity: ✅ Time: O(n) — single pass ✅ Space: O(1) — no extra array, truly in-place Sometimes the constraint IS the optimization. Working within limits pushes us to think smarter! 🧠 #LeetCode #DSA #TwoPointer #Java #ADA #PBL2 #LeetCodeChallenge #Day3of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #MoveZeroes
To view or add a comment, sign in
-
-
🚀 Day 47of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Mirror Distance of an Integer Problem Insight: Given a number, the task is to find the absolute difference between the original number and its reversed form. Approach: • Stored the original number in a temporary variable • Reversed the number using digit extraction (modulo and division) • Calculated the absolute difference between the original and reversed number Time Complexity: O(d), where d = number of digits Space Complexity: O(1) Key Learnings: • Digit manipulation using modulo and division is a powerful technique • Always store the original value before modifying the input • Reversing numbers is a fundamental pattern in many DSA problems Takeaway: Breaking the problem into simple steps makes even tricky-looking logic easy to solve. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 15 of #50DaysLeetCode Challenge Today I solved the “Longest Common Prefix” problem on LeetCode using Java. 🔹 Problem: Find the longest common prefix among an array of strings. If no common prefix exists, return an empty string "". Example: Input: ["flower","flow","flight"] Output: "fl" Input: ["dog","racecar","car"] Output: "" 🔹 Approach I Used: ✔ Took the first string as the initial prefix ✔ Compared it with each string in the array ✔ If mismatch occurs, reduced the prefix step by step ✔ Continued until all strings share the same prefix 🔹 Key Insight: You don’t need complex logic — just keep shrinking the prefix until it matches all strings. 🔹 Concepts Practiced: • String manipulation • Iterative comparison • Edge case handling #LeetCode #DSA #Java #Algorithms #ProblemSolving #CodingChallenge #50DaysOfCode
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 59/100 – LeetCode Challenge 📌 Problem Solved: Remove Duplicates from Sorted Array II (Medium) Today’s problem was a great exercise in in-place array manipulation and two-pointer technique. 💡 Key Idea: Since the array is already sorted, duplicates are adjacent. Instead of removing all duplicates, we allow each element to appear at most twice. 👉 The trick is to compare the current element with the element at index k-2. If they are the same → skip ❌ If different → keep it ✅ ⚙️ Approach: Initialize pointer k = 2 Traverse from index 2 Copy valid elements forward Maintain order without extra space 🧠 What I learned: How to efficiently handle constraints like “at most twice” Importance of thinking in terms of index relationships (k-2) Writing optimal O(n) solutions with O(1) space 📊 Performance: ⚡ Runtime: 0 ms (100%) 💾 Memory: 48.46 MB 💻 Tech Used: Java Consistency is key 🔑 — 59 days done, 41 more to go! #100DaysOfCode #LeetCode #Java #DataStructures #CodingChallenge #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
🚀100 Days of Code Day-26 LeetCode Practice – Remove Duplicates from Sorted Array Solved a classic problem using the Two Pointer Technique 💡 📌 Problem: Given a sorted array, remove duplicates in-place and return the number of unique elements. 🔍 Key Idea: Since the array is sorted, duplicates are adjacent. Using two pointers helps efficiently overwrite duplicates without extra space. ⚡ Complexity: Time → O(n) Space → O(1) 💻 Clean and optimized approach makes this problem a great example of in-place array manipulation! #LeetCode #Java #DataStructures #CodingPractice #ProblemSolving #100DaysOfCode
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