Day 66 - LeetCode Journey Solved LeetCode 167: Two Sum II – Input Array Is Sorted (Medium) today — a great example of how knowing the properties of a sorted array can drastically simplify the solution. Since the array is already sorted in non-decreasing order, we can avoid extra data structures and use a two-pointer approach to find the pair efficiently. 💡 Core Idea: Start with two pointers: • left at the beginning • right at the end Then check the sum of the two numbers: If the sum is equal to the target → solution found If the sum is less than the target → move the left pointer forward If the sum is greater than the target → move the right pointer backward This gradually narrows down the search space until the correct pair is found. ⚡ Key Learning Points: • Leveraging sorted array properties • Efficient use of the two-pointer technique • Reducing time complexity to O(n) • Solving the problem with O(1) extra space Problems like this highlight how choosing the right technique can make solutions clean, fast, and elegant. ✅ Stronger understanding of two-pointer patterns ✅ Better optimization mindset ✅ Improved problem-solving intuition Every problem solved adds another useful pattern to the toolkit 🚀 #LeetCode #DSA #Java #TwoPointers #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperJourney #KeepCoding
Two Sum II - Sorted Array Solution
More Relevant Posts
-
Today I solved LeetCode 145 – Binary Tree Postorder Traversal. 🧩 Problem Summary: Given the root of a binary tree, return the postorder traversal of its nodes' values. In postorder traversal, nodes are visited in the order: Left → Right → Root 💡 Key Concepts Used: Binary Trees Tree Traversal Iterative approach using Stack Depth First Search (DFS) 🧠 Approach: Use a stack to simulate recursion. Traverse to the leftmost node while pushing nodes onto the stack. Peek the node at the top of the stack. If the node has a right child that hasn’t been processed, move to the right subtree. Otherwise, process the node (add it to the result) and mark it as last visited. Repeat until all nodes are processed. This ensures the correct Left → Right → Root traversal order. 📚 What I Learned: How to implement postorder traversal iteratively. Managing traversal state using a stack and lastVisited pointer. Understanding the difference between recursive and iterative tree traversal. Strengthening concepts of Depth First Search (DFS) in binary trees. Exploring tree problems to build a stronger DSA foundation 🌳 Consistency in learning every day 🚀 #LeetCode #DSA #BinaryTree #TreeTraversal #PostorderTraversal #Stack #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Today I solved LeetCode 145 – Binary Tree Postorder Traversal. 🧩 Problem Summary: Given the root of a binary tree, return the postorder traversal of its nodes' values. In postorder traversal, nodes are visited in the order: Left → Right → Root 💡 Key Concepts Used: Binary Trees Tree Traversal Iterative approach using Stack Depth First Search (DFS) 🧠 Approach: Use a stack to simulate recursion. Traverse to the leftmost node while pushing nodes onto the stack. Peek the node at the top of the stack. If the node has a right child that hasn’t been processed, move to the right subtree. Otherwise, process the node (add it to the result) and mark it as last visited. Repeat until all nodes are processed. This ensures the correct Left → Right → Root traversal order. 📚 What I Learned: How to implement postorder traversal iteratively. Managing traversal state using a stack and lastVisited pointer. Understanding the difference between recursive and iterative tree traversal. Strengthening concepts of Depth First Search (DFS) in binary trees. Exploring tree problems to build a stronger DSA foundation 🌳 Consistency in learning every day 🚀 #LeetCode #DSA #BinaryTree #TreeTraversal #PostorderTraversal #Stack #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 76 - LeetCode Journey Solved LeetCode 83: Remove Duplicates from Sorted List (Easy) today — a straightforward problem that strengthens linked list traversal and in-place modification. Since the list is already sorted, duplicate elements will always be adjacent, which makes the approach simpler. 💡 Core Idea: Traverse the list and compare each node with its next node. • If values are equal → skip the next node • If not → move forward This way, we remove duplicates without using extra space. ⚡ Key Learning Points: • Leveraging the sorted property of the list • Modifying linked list in-place • Avoiding unnecessary memory usage • Maintaining O(n) time and O(1) space This is a simple but important pattern that often appears in variations like: Remove all duplicates (not just extra ones) Remove duplicates from unsorted lists (using hashing) ✅ Better understanding of linked list traversal ✅ Stronger control over pointer updates ✅ Improved confidence in in-place operations Simple problems like this help sharpen the fundamentals that matter in bigger questions 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 70 - LeetCode Journey Solved LeetCode 88: Merge Sorted Array (Easy) today — a classic problem that focuses on array manipulation and the two-pointer technique. The challenge is to merge two sorted arrays into one sorted array without using extra space, by modifying nums1 in-place. 💡 Core Idea: Instead of merging from the beginning, we start from the end of the arrays. Why? Because nums1 already has extra space at the end to accommodate elements from nums2. We use three pointers: • i → last valid element in nums1 • j → last element in nums2 • k → last position of merged array At each step, we place the larger element at position k, ensuring the array remains sorted. ⚡ Key Learning Points: • Using the two-pointer technique from the end • Performing in-place array merging • Maintaining O(m + n) time complexity • Avoiding unnecessary extra space This problem is a great reminder that sometimes changing the direction of traversal makes the solution much simpler. ✅ Better understanding of array manipulation ✅ Stronger grasp of two-pointer techniques ✅ Improved problem-solving efficiency Small problems like this build strong fundamentals for bigger challenges 🚀 #LeetCode #DSA #Java #TwoPointers #Arrays #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 77 - LeetCode Journey Solved LeetCode 82: Remove Duplicates from Sorted List II (Medium) today — a more advanced version of the duplicate removal problem. Unlike the basic version, here we need to remove all nodes that have duplicates, leaving only distinct values. 💡 Core Idea: Use a dummy node + two pointers approach. • A dummy node helps handle edge cases (like duplicates at the head) • Use prev to track the last confirmed unique node • Use curr to traverse the list When duplicates are found: → Skip all nodes with that value → Connect prev.next to the next distinct node If no duplicate: → Simply move prev forward ⚡ Key Learning Points: • Importance of a dummy node in linked list problems • Handling edge cases at the head • Removing elements completely (not just skipping extras) • Clean pointer manipulation with O(n) time and O(1) space This problem highlights the difference between: Keeping one copy (Easy version) Removing all duplicates (Medium version) That small change makes the logic significantly more interesting. ✅ Stronger understanding of pointer control ✅ Better handling of edge cases ✅ Improved problem-solving depth in linked lists These variations are where real learning happens 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 11 – #50DaysLeetCodeChallenge Today I solved the 3Sum problem. 📌 Problem Statement Given an integer array nums, return all the unique triplets [nums[i], nums[j], nums[k]] such that: i ≠ j ≠ k nums[i] + nums[j] + nums[k] = 0 ⚠️ The solution must not contain duplicate triplets. Example: Input: [-1,0,1,2,-1,-4] Output: [[-1,-1,2], [-1,0,1]] 💡 Approach I Used – Sorting + Two Pointers 1️⃣ Sort the array 2️⃣ Fix one element i 3️⃣ Use two pointers: left = i + 1 right = end of array 4️⃣ Check the sum: If sum == 0 → add triplet If sum < 0 → move left++ If sum > 0 → move right-- 5️⃣ Skip duplicates to avoid repeated triplets ⚙️ Key Idea Reduce the problem from 3Sum → 2Sum (using two pointers) Sorting helps in efficient traversal and duplicate handling 🧠 What I learned today ✔️ How sorting simplifies complex problems ✔️ Converting problems into smaller subproblems (3Sum → 2Sum) ✔️ Handling duplicates carefully From simple arrays → advanced pointer techniques 🚀 Consistency is making a difference! #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
100 Days of Code Day-21 🔗 Merging Two Sorted Linked Lists – LeetCode Problem Today, I worked on a classic problem of merging two sorted linked lists into one sorted list. 💡 The approach is simple: Compare elements from both lists Attach the smaller node to the result Continue until all nodes are merged 📌 This problem helped me strengthen my understanding of: • Linked Lists • Two-pointer technique • Efficient problem-solving 🚀 Time Complexity: O(n + m) 🚀 Space Complexity: O(1) Consistency is key in mastering Data Structures & Algorithms! #leetcode #datastructures #java #coding #problemSolving #learning #developers
To view or add a comment, sign in
-
-
🚀 LeetCode Problem || Fancy Sequence (1622) Today I worked on an interesting design problem where we need to maintain a sequence that supports the following operations efficiently: • append(val) → Append a number to the sequence • addAll(inc) → Add a value to every element in the sequence • multAll(m) → Multiply every element by a value • getIndex(idx) → Retrieve the value at a specific index 💡 Optimization Idea Instead of modifying every element, we represent the sequence transformation using a mathematical form: value=a×x+bvalue = a \times x + bvalue=a×x+bWhere: a tracks the cumulative multiplication b tracks the cumulative addition x is the stored base value #LeetCode #Java #Algorithms #DataStructures #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 72 - LeetCode Journey Solved LeetCode 206: Reverse Linked List (Easy) today — one of the most fundamental problems for understanding linked list manipulation and pointer handling. The task is to reverse a singly linked list so that the direction of all pointers is flipped. 💡 Core Idea: Traverse the list once and reverse the pointer of each node. We maintain three pointers: • prev → previous node (initially null) • curr → current node being processed • next → stores the next node before changing links At each step: Save the next node Reverse the current node’s pointer Move both pointers forward This continues until we reach the end of the list. ⚡ Key Learning Points: • Understanding pointer manipulation in linked lists • Reversing links without extra space • Maintaining O(n) time complexity and O(1) space • Building a foundation for many advanced linked list problems This is a must-know pattern because it appears frequently in variations like: Reverse Linked List II Reverse Nodes in k-Group Palindrome Linked List ✅ Stronger understanding of linked list pointers ✅ Improved confidence with pointer manipulation ✅ Solid foundation for advanced linked list questions Small problems like this build the fundamentals of strong data structure skills 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 44 of #100DaysOfCode Solved 1011. Capacity To Ship Packages Within D Days on LeetCode 📦 🧠 Key Insight: We need to find the minimum ship capacity such that all packages can be shipped within D days. This is a classic case of Binary Search on Answer. ⚙️ Approach: 1️⃣ The minimum capacity = max(weight) (since one package must fit) 2️⃣ The maximum capacity = sum of all weights 3️⃣ Apply Binary Search between these bounds 4️⃣ For each capacity mid, simulate shipping: 🔹Keep adding weights until capacity exceeds 🔹Move to the next day when exceeded 5️⃣ If we can ship within D days → try smaller capacity 6️⃣ Else → increase capacity This helps us find the minimum valid capacity efficiently. ⏱️ Time Complexity: O(n log(sum)) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Algorithms #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
Explore related topics
- Approaches to Array Problem Solving for Coding Interviews
- Leetcode Problem Solving Strategies
- LeetCode Array Problem Solving Techniques
- Strategies for Solving Algorithmic Problems
- Solving Sorted Array Coding Challenges
- Google SWE-II Data Structures Interview Preparation
- How to Improve Array Iteration Performance in Code
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