Day 58 - LeetCode Journey Solved LeetCode 374: Guess Number Higher or Lower (Easy) today using the Binary Search approach. This problem is a perfect example of how a simple idea can become very efficient with the right approach. Instead of checking every number, we narrow down the search space step by step. Today’s problem reinforced key concepts like: • Applying Binary Search on a defined range • Reducing time complexity from O(n) to O(log n) • Making decisions based on feedback (higher / lower) • Writing clean and optimized logic The idea is straightforward — pick the middle number and adjust the search space based on whether the guess is high or low 💡 This approach ensures we find the answer in the minimum number of steps, making it both efficient and elegant. Every problem, even easy ones, helps strengthen the fundamentals and improve thinking 💯 ✅ Better understanding of binary search ✅ Improved problem-solving efficiency ✅ Stronger DSA foundation Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #BinarySearch #Programming #DeveloperJourney #KeepCoding
LeetCode 374: Binary Search Solution in Java
More Relevant Posts
-
Day 98 of my 100 Days of LeetCode Challenge 🚀 Solved Longest Increasing Subsequence (LIS) — a classic Dynamic Programming + Binary Search problem. The task is to find the length of the longest strictly increasing subsequence in an array. Approach used in my solution (Optimized O(n log n)): • Maintained a list res to store the smallest possible tail value for increasing subsequences of different lengths • If the current number is greater than the last element in res, append it • Otherwise, use binary search to find the correct position and replace the element • The size of res at the end gives the length of LIS Important Insight: The list does not store the actual LIS, but it maintains optimal subsequence tails to guarantee maximum possible length. Time Complexity: O(n log n) Space Complexity: O(n) This problem is a huge milestone in understanding advanced DP optimization techniques. #100DaysOfCode #100DaysOfLeetCode #LeetCode #DynamicProgramming #BinarySearch #LIS #Java #DSA #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
✳️Day 17 of #100DaysOfCode✳️ Solving the Longest Common Subsequence Problem! 🚀 I recently took on the "Longest Common Subsequence" (LCS) challenge on LeetCode—a classic problem that perfectly illustrates the power of Dynamic Programming. Here’s the step-by-step approach I took: ✅ 1. Problem Decomposition: I broke the problem down into smaller sub-problems. If the last characters of two strings match, they contribute to the subsequence; if not, we explore the possibilities by skipping a character from either string. ✅ 2. Recursive Foundation: I started by defining the base case—if either string is empty, the LCS length is 0. ✅ 3. Optimization with Memoization: Pure recursion leads to redundant calculations (overlapping sub-problems). I implemented a 2D array (dp[n][m]) to store results of previously computed states, significantly boosting performance. ✅ 4. Refinement: Fine-tuning the logic to ensure the time and space complexity were balanced for an efficient "Accepted" result . Always learning, always coding. On to the next challenge! 💻 #LeetCode #Java #DynamicProgramming #CodingLife #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
-
🚀 LeetCode Problem Solved: Maximum Number of Vowels in a Substring of Given Length Today I solved LeetCode 1456 – Maximum Number of Vowels in a Substring of Given Length using the Sliding Window Technique. 🔹 Problem Statement: Given a string s and an integer k, find the maximum number of vowels in any substring of length k. 🔹 Approach: Instead of checking every substring separately, I used the Sliding Window algorithm: • Count vowels in the first window of size k • Slide the window forward one character at a time • Add the new character and remove the old one from the count • Track the maximum vowels seen so far This approach optimizes the solution to O(n) time complexity. 📌 Example: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowels, which is the maximum. 💡 Key Concepts Practiced: ✔ Sliding Window Technique ✔ String Traversal ✔ Efficient Problem Solving Consistent DSA practice on LeetCode is helping me improve my algorithmic thinking and coding efficiency. #LeetCode #DSA #SlidingWindow #ProblemSolving #CodingPractice #Java #LearningInPublic #Programming
To view or add a comment, sign in
-
-
🚀 Day 522 of #750DaysOfCode 🚀 Today I solved the LeetCode problem “Minimum Changes To Make Alternating Binary String.” 🔹 Problem: Given a binary string consisting of 0s and 1s, we need to make the string alternating (no two adjacent characters are the same). In one operation, we can flip any character (0 → 1 or 1 → 0). The goal is to find the minimum number of operations required. 🔹 Key Idea: An alternating string can only follow two possible patterns: 1️⃣ 010101... 2️⃣ 101010... So we: Count mismatches assuming the string starts with '0'. The other pattern mismatches will be n - mismatch. The minimum of these two values gives the answer. 🔹 Time Complexity: O(n) – we traverse the string once. 📌 Example Input: "1111" Possible alternating strings → "0101" or "1010" Minimum operations → 2 Problems like this highlight how pattern observation can simplify the solution. #leetcode #programming #coding #java #softwaredevelopment #dsa #problemSolving #750DaysOfCode
To view or add a comment, sign in
-
-
📌 𝗥𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 𝗔𝗻𝗱 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 🍀 👉 Question : 2698. Find the Punishment Number of an Integer 👉 Link : https://lnkd.in/gVVu4SJ7 🌏Don't forget to check the Qn sol code on my Github profile! 🌈 https://lnkd.in/g8t3cQ6N 🔥 Key Points of the Code: : 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 : Backtracking / Recursive Partitioning ✔ Iterate 1 → n ✔Compute square of each number ✔Recursively split digits of square ✔Check if sum of split parts = original number ✔If yes → add square to result ✔ Uses backtracking with recursion 🕒 O(n⋅3^(logn)) --> (Exponential growth due to recursion) 💾 Space: O(logn) ---> (Recursive depth) 💖 Gratitude Corner A huge shoutout to Mazhar Imam Khan🙌, Code Help by Love Babbar🙌 for sharing valuable insights and motivating coders like me to keep pushing forward #codestorywithMIK #geeksforgeeks #takeuforward #Codehelp #Telusko #Java #Math #CodingChallenge #KeepGrinding #LeetCode #Problem #Coding #DSA #Algorithms #POTD #Tech #CompetitiveProgramming #KeepCoding #dailyproblem #DataStructres #code #approaches #algorithms
To view or add a comment, sign in
-
🚀 Day 16/100 Days of Code Challenge Solved the classic “Sort Colors” problem (LeetCode 75) today! 🎯 🔹 Problem Summary: Given an array containing 0s, 1s, and 2s (representing colors), sort them in-place without using built-in sort. 🔹 Approach Used: Maintained three pointers: low, mid, high Efficiently partitioned the array in a single pass 🔹 Key Learning: ✔️ In-place sorting can be done in O(n) time ✔️ Using pointers smartly avoids extra space 💡 Time Complexity: O(n) 💡 Space Complexity: O(1) 🔹 Code Highlight : Used swapping and pointer movement to organize elements in one traversal. Consistency is the key 🔑 — one step closer to mastering DSA! #Day16 #100DaysOfCode #DSA #Java #CodingChallenge #LeetCode #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 14 of My LeetCode Journey Today I solved an interesting problem on LeetCode: “Check if Binary String Has at Most One Segment of Ones.” 🧠 Problem Statement: Given a binary string, check whether it contains at most one continuous segment of '1's. 📌 Example: Input: "111000" → ✅ True Input: "110011" → ❌ False 💡 Key Idea: If the string contains "01", it means the sequence of `1`s ended and `0`s started. If another `1` appears later, there are multiple segments of `1`s, which makes the answer false. 🎯 Learning: Many coding problems become easier when we look for patterns instead of writing complex logic. Consistency is the key to improving problem-solving and programming skills. #LeetCode #Java #CodingJourney #ProblemSolving #100DaysOfCode #SoftwareDevelopment
To view or add a comment, sign in
-
-
Friday Learning: A Simple Trick That Saves Time Today I solved LeetCode 3567 — and almost overcomplicated it. At first, I thought: “Compare every pair inside the submatrix” → O(n²) But then I realized something simple 👇 Sort the elements. Once sorted, the minimum absolute difference will ALWAYS be between adjacent values. Approach: • Extract k × k submatrix • Remove duplicates (HashSet) • Sort elements • Check adjacent differences Complexity: O(m × n × k² log k) Lesson: Sometimes the best optimization isn’t a complex data structure… It’s just recognizing the pattern. Building consistency, one problem at a time. - Ishwar Chandra Tiwari | CodeWithIshwar #leetcode #dsa #programming #java #developers #coding #buildinpublic
To view or add a comment, sign in
-
🚀 Day 27/60 — LeetCode Discipline Problem Solved: Length of Last Word Difficulty: Easy Today’s problem looked simple, yet it emphasized a subtle but important skill — handling edge cases cleanly. The goal was to find the length of the last word in a string, ignoring any trailing spaces. Instead of splitting the string or using extra space, the solution efficiently traverses from the end, skipping unnecessary characters and counting only what truly matters. It’s a reminder that strong coding is not always about complexity — sometimes, it’s about precision and clarity in small details. 💡 Focus Areas: • Practiced string traversal from end • Improved handling of trailing spaces • Reinforced clean and efficient logic • Avoided unnecessary extra space usage • Strengthened edge-case thinking ⚡ Performance Highlight: Achieved 0 ms runtime (100% performance). Small problems, when approached with discipline, sharpen the instincts that solve big ones. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Java #Developers #Consistency #TechJourney #LearnToCode
To view or add a comment, sign in
-
-
🚀 Day 525 of #750DaysOfCode 🚀 💡 LeetCode 1980: Find Unique Binary String Today’s problem was an interesting one involving binary strings and a clever observation. We are given n unique binary strings of length n, and the task is to return any binary string of length n that does not exist in the given array. 🔎 Approach I Used I applied a concept similar to Diagonalization. Traverse the array from 0 → n-1 Look at the i-th character of the i-th string Flip it (0 → 1 or 1 → 0) Append the flipped character to build a new string This guarantees the newly created string differs from every string in the list at least at one position, ensuring it is unique and not present in the array. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) This approach works efficiently because the constraints are small and we only need to ensure one position difference with each string. Problems like this highlight how a simple observation can eliminate brute force completely. #leetcode #coding #programming #java #datastructures #algorithms #problemSolving #developer #codingchallenge #750DaysOfCode
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