Day 9 of Daily DSA 🚀 Solved LeetCode 11: Container With Most Water ✅ 🔍 Approach: Used the two-pointer technique to efficiently calculate the maximum area. Started with pointers at both ends Calculated area using min height × width Moved the pointer with the smaller height to optimize the result This avoids brute force and ensures an optimal solution. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 5 ms (Beats 80.63%) • Memory: 77.19 MB (Beats 92.56%) A great example of how the right observation can turn a problem into a clean solution. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #DailyCoding
LeetCode 11: Container With Most Water Solution
More Relevant Posts
-
Day 62/100 – LeetCode Challenge ✅ Problem: #401 Binary Watch Difficulty: Easy Language: Java Approach: Brute Force with Bit Counting Time Complexity: O(12 × 60) = O(720) → O(1) Space Complexity: O(1) for result storage Key Insight: Binary watch has 4 LEDs for hours (0-11) and 6 LEDs for minutes (0-59). Each possible time combination has a total bit count = hour bits + minute bits. If total bits equals turnedOn, it's a valid time. Solution Brief: Nested loops over all possible hours (0-11) and minutes (0-59). Used Integer.bitCount() to count set bits in hour and minute. Formatted time string with leading zero for minutes when needed. #LeetCode #Day62 #100DaysOfCode #BitManipulation #Java #Algorithm #CodingChallenge #ProblemSolving #BinaryWatch #EasyProblem #BruteForce #TimeFormatting #DSA
To view or add a comment, sign in
-
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 87/100 – LeetCode Challenge ✅ Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Direct Matrix Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) for result matrix Key Insight: Transpose swaps rows and columns: transposed[i][j] = matrix[j][i]. New matrix dimensions: col × row (original dimensions swapped). Solution Brief: Created result matrix with dimensions col × row. Nested loops assign each element to swapped position. Returned transposed matrix. #LeetCode #Day87 #100DaysOfCode #Matrix #Java #Algorithm #CodingChallenge #ProblemSolving #TransposeMatrix #EasyProblem #Array #2DArray #DSA
To view or add a comment, sign in
-
-
Day 10 of Daily DSA 🚀 Solved LeetCode 190: Reverse Bits ✅ 🔍 Approach: Worked with the 32-bit representation of the given integer: • Converted the number into a fixed 32-bit binary string • Used a two-pointer technique to reverse the bits • Converted the reversed binary back to an unsigned integer This approach keeps the logic simple while ensuring correctness for signed integers. ⏱ Complexity: • Time: O(32) = O(1) (constant time) • Space: O(32) = O(1) 📊 LeetCode Stats: • Runtime: 9 ms • Memory: 43.46 MB A good reminder that clarity matters more than micro-optimizations when learning bit manipulation. #DSA #LeetCode #Java #BitManipulation #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 73/100 of my DSA Journey ✅ Problem solved today: LeetCode 1461 – Check If a String Contains All Binary Codes of Size K 🧠 What I focused on: Using a HashSet to store all substrings of length k Sliding window technique to generate substrings efficiently Understanding why we only need to check if the number of unique substrings equals 2^k Handling edge cases when string length is smaller than k This problem nicely combined strings + sliding window + hashing logic. 📌 Key takeaway: Sometimes the solution is just counting unique patterns efficiently. 📈 Day 73 done. Consistency continues. #LeetCode #DSA #SlidingWindow #Strings #Hashing #Java #ProblemSolving #Consistency #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
Day 20 of Daily DSA 🚀 Solved LeetCode 179: Largest Number ✅ Approach: Converted all integers to strings and used a custom comparator while sorting. For two numbers a and b, we compare: a + b vs b + a This ensures the order that forms the largest possible number. Edge Case Handled 💡 If the highest element after sorting is "0", then the entire array contains zeros → return "0" instead of "000". ⏱ Complexity: • Time: O(n log n) — sorting with custom comparator • Space: O(n) — string array 📊 LeetCode Stats: • Runtime: 6 ms (Beats 96.21%) ⚡ • Memory: 44.96 MB (Beats 76.86%) Comparator-based problems really sharpen logical thinking 🔥 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Sorting #Consistency
To view or add a comment, sign in
-
-
Day 16/30 – Sort Colors 🚀 Solved: Sort an array of 0s, 1s, and 2s in-place. Technique Used: Dutch National Flag Algorithm 🇳🇱 Pointers: • low → boundary for 0 • mid → current element • high → boundary for 2 Single pass. Constant space. Pure pointer manipulation. Time Complexity: O(n) Space Complexity: O(1) This problem is a masterclass in two-pointer control. #30DaysOfCode #Java #DSA #TwoPointers #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 17 Solved LeetCode 162 – Find Peak Element using Binary Search approach. ⚠️ Interesting Trap: I initially used the common condition while(left <= right), which caused an infinite loop in this problem. When left == right, mid = left, and right = mid doesn't change — so the loop never ends. ✅ Fix: Using while(left < right) ensures the pointers move correctly and the loop terminates. 💡 A small change in the loop condition can make a huge difference in algorithm behavior. ✔️ Time Complexity: O(log n) ✔️ Space Complexity: O(1) Accepted | Runtime: 0ms #Day17 #LeetCode #DSA #BinarySearch #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Solved LeetCode #206 — Reverse Linked List. Problem: Given the head of a singly linked list, reverse the list and return the new head. Example: [1,2,3,4,5] → [5,4,3,2,1] Approach Used: Iterative Pointer Reversal Traverse the list while maintaining three pointers: • prev → stores the previous node • head → current node being processed • next → temporarily stores the next node For each node: Store next = head.next Reverse the pointer → head.next = prev Move pointers forward Continue until the list ends. prev becomes the new head of the reversed list. Complexity • Time Complexity: O(n) • Space Complexity: O(1) A classic linked list problem that strengthens pointer manipulation skills. #LeetCode #DSA #Algorithms #Java #CodingInterview #SoftwareEngineering
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