Stop writing code that “just works.” Day 45 / 100 Days of DSA Problem: Find a pair from two arrays whose sum is closest to a target. First approach: Nested loops. Better approach: Two pointers (since arrays are sorted). Move intelligently based on the sum. Time Complexity: O(n + m). Same answer. Smarter thinking. Day 45 lesson: Don’t stop at “it works.” Push for optimal. #Day45 #100DaysOfCode #DSA #Java #ProblemSolving
Mohd Ismaeel’s Post
More Relevant Posts
-
🚀 Day 84/100 – 𝐒𝐞𝐚𝐫𝐜𝐡 𝐢𝐧 𝐑𝐨𝐭𝐚𝐭𝐞𝐝 𝐒𝐨𝐫𝐭𝐞𝐝 𝐀𝐫𝐫𝐚𝐲 𝐈𝐈 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Binary search works great on sorted arrays, but duplicates introduce ambiguity — making it harder to decide which half is sorted. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Use modified binary search Identify the sorted half Handle duplicates by shrinking the search space ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Find 𝐦𝐢𝐝 If 𝐭𝐚𝐫𝐠𝐞𝐭 𝐟𝐨𝐮𝐧𝐝 → 𝐫𝐞𝐭𝐮𝐫𝐧 𝐭𝐫𝐮𝐞 𝐇𝐚𝐧𝐝𝐥𝐞 𝐝𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞𝐬 (𝐥𝐨𝐰++) Check which half is sorted Narrow down search accordingly #Day84 #100DaysOfCode #Java #DSA #LeetCode #BinarySearch #CodingJourney
To view or add a comment, sign in
-
-
𝗬𝗼𝘂 𝗵𝗮𝘃𝗲 𝗯𝗲𝗲𝗻 𝘂𝘀𝗶𝗻𝗴 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 𝘄𝗿𝗼𝗻𝗴. It is not just for sorted arrays. The real definition — "Eliminate HALF the search space with each decision." That one shift in thinking unlocks 20+ LeetCode problems. Swipe to see the template, live code, and 7 problems you can now solve with one pattern. 👇 Save this. 🔖 #DSA #BinarySearch #Java #LeetCode #CodingInterview #DebugWithPurpose
To view or add a comment, sign in
-
🧠 Day 30 / 100 – DSA Practice Solved Remove Duplicates from Sorted List on LeetCode 🔗✅ 🔹 Problem Insight: Given a sorted linked list, remove duplicates so each element appears only once. 🔹 Approach: Used a single pointer traversal: Compared current node with next node Skipped duplicate nodes by updating links Leveraged the fact that the list is already sorted 🔹 Complexity: Time → O(n) Space → O(1) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Consistency builds confidence 💪🚀 #Day30 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
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
-
-
🚀 DSA Consistency – Day 54 Solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode. The task is to determine whether a binary string contains at most one contiguous block of 1s. Example: 1100111 → ❌ False (two segments of 1s) 111000 → ✅ True (only one segment) 🔹 Approach 1: Traverse the String Idea: While traversing the string, once we encounter a 0, no 1 should appear afterward. If 1 appears again, it means a second segment of ones has started. 🔹 Approach 2: String Pattern Check A binary string with only one segment of 1s should never contain "01" followed by another 1. So, we simply check for the pattern "01". Both the approaches have same complexities: Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 55 of #100DaysOfCode Solved 147. Insertion Sort List on LeetCode 🔗 🧠 Key Insight: We apply the classic Insertion Sort, but on a linked list instead of an array. The challenge is handling pointer manipulation efficiently. ⚙️ Approach: 1️⃣ Create a dummy node to act as the start of the sorted list 2️⃣ Traverse the original list node by node 3️⃣ For each node: Find its correct position in the sorted part Insert it there by updating pointers 🔁 This builds a sorted list incrementally ⏱️ Time Complexity: O(n²) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Sorting #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 11 of #Leetcode75 LeetCode #392 – Is Subsequence | Two Pointer Approach Today I solved “Is Subsequence” (Easy) and revised an important concept — the Two Pointer Technique. 🔎 Problem Summary: Given two strings s and t, determine whether s is a subsequence of t. A subsequence maintains the relative order of characters but doesn’t need to be continuous. 💡 Key Insight: Instead of using extra space or complex logic, we can solve this efficiently using two pointers: ✔ One pointer for s ✔ One pointer for t ✔ Move forward and match characters in order ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This problem reinforces how powerful simple logic can be when applied correctly. Consistency > Complexity 💪 Excited to keep improving step by step! #LeetCode #DSA #Java #CodingPractice #ProblemSolving #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
-
🔥 Day 98 of #100DaysOfCode Today’s challenge: LeetCode – Search in Rotated Sorted Array II 🔄🔍 📌 Problem Summary You are given a rotated sorted array that may contain duplicates. Your task is to determine whether a target exists in the array. Example: Input: nums = [2,5,6,0,0,1,2], target = 0 Output: true 🧠 Approach Used: Linear Search In this implementation, we simply iterate through the array and check if the element matches the target. ⚙️ Logic for(int i = 0; i < nums.length; i++){ if(nums[i] == target){ return true; } } return false; 💡 Explanation Traverse the array from start to end If the target is found → return true If the loop finishes → return false ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🚀 Performance Runtime: 0 ms Memory: 44.9 MB 🧠 Learning This problem is a variation of Search in Rotated Sorted Array, but with duplicates allowed. While a Binary Search solution exists, duplicates can break the strict ordering and make the logic more complex. A simple linear scan ensures correctness in all cases. Only 2 days left to complete #100DaysOfCode 🚀 Almost at the finish line! On to Day 99 🔥 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
-
#day333 of #1001daysofcode problem statement (0257): Binary Tree Paths 💡 Approach: Used DFS recursion to explore all root-to-leaf paths in the binary tree. While traversing, I kept building the path string. When a leaf node is reached, the complete path is added to the result list. Example path format: 1->2->5 ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(h) — recursion stack (h = height of the tree) Consistency in solving one problem every day 📈 #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
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