Day 9 of Daily DSA 🚀 Solved LeetCode 334: Increasing Triplet Subsequence ✅ 🔍 Approach: Implemented a greedy single-pass solution by tracking the smallest (a) and second smallest (b) and another smallest (c)values seen so far. Update a if a smaller value appears Update b if the value is greater than a but smaller than b If a value greater than both is found → update c → triplet exists No extra arrays, no sorting—just clean logic. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 2 ms (Beats 98.96%) ⚡ • Memory: 122.66 MB (Beats 56.98%) Great example of how a simple greedy observation make clean solution. #DSA #LeetCode #Java #GreedyAlgorithm #ProblemSolving #Consistency #DailyCoding
LeetCode 334: Increasing Triplet Subsequence Solution in Java
More Relevant Posts
-
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
-
-
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
-
-
🚀 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 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
To view or add a comment, sign in
-
-
Day 12 of Daily DSA 🚀 Solved LeetCode 704: Binary Search ✅ Approach: Used the classic binary search technique on a sorted array. Initialized start and end pointers and repeatedly narrowed the search space by comparing the target with the middle element. Calculated mid using start + (end - start) / 2 to avoid overflow and ensure correctness. This approach efficiently reduces the search range and guarantees optimal performance. ⏱ Complexity: • Time: O(log n) — search space halves every iteration • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 48.54 MB (Beats 29.13%) A solid example of how understanding fundamentals leads to maximum efficiency. #DSA #LeetCode #Java #BinarySearch #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 511 of #750DaysOfCode 🚀 🔢 762. Prime Number of Set Bits in Binary Representation (LeetCode - Easy) Today’s problem was a beautiful mix of bit manipulation + prime checking. 🧠 Problem Summary Given two integers left and right, count how many numbers in that range have a prime number of set bits (1s) in their binary representation. 📌 Example: 21 → Binary: 10101 Set bits = 3 → 3 is prime ✅ 💡 Key Observations We need to: Convert each number to binary. Count the number of set bits. Check if that count is prime. Since right ≤ 10^6, the maximum number of set bits possible is 20 (because 2²⁰ ≈ 10⁶). 👉 So instead of checking prime again and again, we can pre-store prime numbers up to 20. 🔥 What I Practiced Today Using Integer.bitCount() efficiently Understanding binary representations deeply Optimizing prime checks for small ranges Clean looping logic 🎯 Time Complexity O(N * sqrt(K)) Where: N = right - left K ≤ 20 (max set bits) So practically very efficient 🚀 💬 Takeaway Sometimes an “Easy” problem is about combining two simple concepts correctly: 👉 Bit manipulation 👉 Prime number checking Consistency > Difficulty. #750DaysOfCode #Day511 #LeetCode #Java #BitManipulation #PrimeNumbers #ProblemSolving #DataStructuresAndAlgorithms
To view or add a comment, sign in
-
-
Day 67/100 – LeetCode Challenge ✅ Problem: #228 Summary Ranges Difficulty: Easy Language: Java Approach: Single Pass with Range Detection Time Complexity: O(n) Space Complexity: O(1) excluding output Key Insight: Track start of current consecutive range. When gap found (next ≠ previous + 1), close current range: Single number if start == previous Range "start → previous" otherwise Solution Brief: Iterated through array comparing consecutive elements. Detected breaks in consecutive sequences. Formatted ranges appropriately with arrow for multi-number ranges. Added final range after loop. #LeetCode #Day67 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #SummaryRanges #EasyProblem #RangeDetection #SinglePass #DSA
To view or add a comment, sign in
-
-
Day 12/30 – LeetCode streak Today’s problem: Number of Steps to Reduce a Number in Binary Representation to One Rules are simple: if the number is even, divide by 2; if it’s odd, add 1. But doing this by simulating the whole number each time is slow and messy. The trick is to walk the binary string from right to left and just count how many operations each bit contributes, while carrying a 1 when we “add 1”: - Ignore index 0 (most significant bit); we stop at 'i > 0'. - For each bit, compute 'bit = (s.charAt(i) - '0') + carry'. - If 'bit' is '1', it’s effectively odd → we need '+1' then '/2' → 'steps += 2' and set 'carry = 1'. - If 'bit' is '0' or '2', it’s even → just '/2' → 'steps += 1', 'carry' stays as is. - After the loop, if there’s still a carry, add one more step because we effectively turned something like '"111"' into '"1000"' and need one last divide to reach '1'. Day 12 takeaway: Instead of repeatedly mutating the number, counting how many times each bit causes “+1 then /2” vs “just /2” gives an O(n), no-conversion solution that feels much cleaner once the carry idea clicks. #leetcode #dsa #java #bitmanipulation #consistency
To view or add a comment, sign in
-
-
#Day28 of #365DaysOfCode Today’s LeetCode practice: 🔹 Word Search (LeetCode 79) Solved a backtracking problem where I had to check whether a given word exists in a 2D board by moving horizontally or vertically through adjacent cells. 💡 Key Insight: Start exploring from every cell. If the character matches the current letter of the word, move in all 4 possible directions. Mark the cell as visited and revert the change if the path doesn’t lead to a solution. On to Day 29 🔥 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #Backtracking #Recursion
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