Day 46 of #100DaysOfLeetCode 💻✅ Solved #374. Guess Number Higher or Lower problem in Java. Approach: • Used Binary Search to efficiently guess the number. • Calculated mid using low + (high - low) / 2 to avoid overflow. • Used the guess(mid) API to check if the number is higher, lower, or correct. • Updated the search range accordingly until the number was found. Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.68 MB (Beats 97.84% submissions) Key Learning: ✓ Practiced implementing binary search on a real problem ✓ Learned how to safely calculate mid to prevent integer overflow ✓ Strengthened problem-solving skills with search algorithms Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
Java Binary Search Solution for LeetCode #374
More Relevant Posts
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 63 of #100DaysOfLeetCode 💻✅ Solved #2085. Count Common Words With One Occurrence problem in Java. Approach: • Iterated through each word in the first array • Avoided duplicate checks by ensuring each word is processed only once • Counted occurrences of the current word in both arrays • If the word appears exactly once in both arrays, incremented the result • Returned the final count Performance: ✓ Runtime: 88 ms (Beats 7.45% submissions) ✓ Memory: 46.06 MB (Beats 93.07% submissions) Key Learning: ✓ Practiced handling duplicates and frequency counting ✓ Improved understanding of string comparison in arrays ✓ Learned importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 92 – #100DaysOfCode Qn. Combination Sum III Today I worked on the Combination Sum III problem using recursion and backtracking in Java. 🔹 Problem Summary: Find all possible combinations of k numbers that add up to n, using numbers 1–9 only once. 🔹 My Approach: Used recursion to explore all possible number combinations. Maintained a running sum and a temporary list. When the sum equals n and the list size equals k, the combination is added to the result. Used a HashSet to avoid duplicate combinations. 🔹 Key Learning: This problem helped me strengthen my understanding of: Backtracking Recursive decision trees Managing state during recursion (adding/removing elements) 📌 Next Goal: Optimize the solution further by avoiding the HashSet and pruning unnecessary recursive calls. #Day92 #LeetCode #DSA #Java #Recursion #Backtracking #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 20/100 – #100DaysOfCode Challenge Today’s problem: Upper Bound using Binary Search 📌 Learned how to find the smallest index where element > x in a sorted array. 📌 Improved understanding of Binary Search patterns. 💡 Key Takeaways: ✔ Efficient searching in O(log n) time ✔ Handling edge cases when element doesn’t exist ✔ Strengthened problem-solving mindset 🧠 Example: Array → [3,5,8,15,19], x = 3 Output → 1 (first element greater than 3 is 5) 💻 Implemented in Java using Binary Search Consistency is the real game 💯 Slow progress is still progress 🚶♂️ #Day20 #100DaysOfCode #DSA #BinarySearch #Java #CodingJourney #TakeUForward
To view or add a comment, sign in
-
-
Day 64 of #100DaysOfLeetCode 💻✅ Solved #724. Find Pivot Index problem in Java. Approach: • Calculated the total sum of the array • Maintained a variable left to track left sum • For each index, computed right sum as total - left - nums[i] • Compared left and right sums • If both are equal, returned the index as pivot • Updated left sum by adding current element Performance: ✓ Runtime: 1 ms (Beats 98.68% submissions) 🚀 ✓ Memory: 47.58 MB (Beats 32.00% submissions) Key Learning: ✓ Learned prefix sum technique for efficient calculations ✓ Practiced reducing time complexity from O(n²) to O(n) ✓ Strengthened understanding of array traversal and sum logic Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 70 of #100DaysOfLeetCode 💻✅ Solved #3136. Valid Word problem in Java. Approach: • Checked if the word length is at least 3 • Traversed each character in the string • Ensured all characters are either letters or digits • Checked for presence of at least one vowel • Checked for presence of at least one consonant • Returned true only if all conditions are satisfied Performance: ✓ Runtime: 1 ms (Beats 99.62% submissions) 🚀 ✓ Memory: 43.08 MB (Beats 93.16% submissions) Key Learning: ✓ Practiced string validation with multiple conditions ✓ Learned efficient use of built-in character functions ✓ Strengthened logic building for edge case handling Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode 💻✅ Solved #506. Relative Ranks problem in Java. Approach: • Iterated through each player's score • Compared it with all other scores to determine its rank • Increased rank whenever a higher score was found • Assigned medals for top 3 ranks: Gold, Silver, Bronze • Converted remaining ranks to string and stored in result array Performance: ✓ Runtime: 124 ms (Beats 5.06% submissions) ✓ Memory: 46.76 MB (Beats 99.84% submissions) Key Learning: ✓ Understood ranking logic using comparison ✓ Practiced nested loop approach for problem solving ✓ Learned the importance of optimizing time complexity Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 47 of #100DaysOfLeetCode 💻✅ Solved #101. Symmetric Tree problem in Java. Approach: • Used recursion to compare the left and right subtrees of the root • If both nodes are null, the tree is symmetric at that level • If one node is null and the other is not, the tree is not symmetric • Compared the values of both nodes • Recursively checked left.left with right.right and left.right with right.left to verify mirror structure Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.62 MB (Beats 48.60% submissions) Key Learning: ✓ Practiced mirror comparison in binary trees ✓ Learned how recursion can verify symmetry between two subtrees ✓ Strengthened understanding of tree traversal and structural comparison Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 36 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (Peak Finding) 🧩 Problem Solved: Find Peak Element Problem: Given an array, find a peak element (an element greater than its neighbors) and return its index. Approach: Used Binary Search by comparing the middle element with its neighbors. Based on the increasing or decreasing slope, moved towards the side where a peak must exist, reducing the search space efficiently. Key Learning: ✔️ Applying binary search on unsorted arrays using patterns ✔️ Understanding how slope direction guides decisions ✔️ Solving peak problems in O(log n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 33 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Index Manipulation 🧩 Problem Solved: Shuffle the Array Problem: Given an array in the form [x1, x2, ..., xn, y1, y2, ..., yn], rearrange it to [x1, y1, x2, y2, ..., xn, yn]. Approach: Used two pointers to track elements from the first and second halves of the array, then alternately placed them into a new array to achieve the required shuffle pattern. Key Learning: ✔️ Managing multiple pointers in array problems ✔️ Practicing index-based rearrangement ✔️ Maintaining correct ordering while constructing a new array If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
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