Solved Longest Subarray with At Most 2 Distinct Elements using Sliding Window.
Two pointers + unordered_map.
Even though thereโs a while loop inside a for loop, it still runs in O(n) because both pointers move only forward.
Simple idea, powerful result ๐ฅ
#DSA#Coding
Solved LeetCode 1404 โ Number of Steps to Reduce a Number in Binary Representation to One ๐ป๐ฅ
Binary simulation + carry handling = clean O(n) solution.
String traversal from right to left makes it elegant.
#LeetCode#DSA#Binary#Coding#100DaysOfCode
Cracked 148. Sort List ๐ฅ
Sorted a linked list in ascending order using Merge Sort (fast & slow pointer to split + merge step).
โฑ Time: O(n log n)
๐ฆ Space: O(1) (constant extra space)
Clean pointer manipulation. No array conversion.
#LeetCode#DataStructures#LinkedList
LeetCode 21 โ Merge Two Sorted Lists โ
Used dummy node + iterative pointer approach to merge in O(n + m) time.
Clean pointer manipulation makes it simple & efficient.
Linked Lists getting stronger ๐ช
#LeetCode21#DSA#LinkedList#Cpp
Solved #42 โ Trapping Rain Water ๐ง๐ฅ
Turned bars into boundaries and gaps into gallons.
Calculated trapped water using left & right max heights โ clean O(n) solution.
When elevation rises, logic must rise higher ๐
#LeetCode#DSA#CPP#ProblemSolving
Solved LeetCode 868 โ Binary Gap โ
Used pure bit manipulation instead of converting to string ๐ฅ
Tracked positions of consecutive 1s using:
n & 1
Right shift n >>= 1
Stored last seen index
Time: O(log n)
Space: O(1)
Bit tricks > string conversion ๐ช
#LeetCode#DSA
Solved LeetCode 762 โ Prime Number of Set Bits โ
Optimized by:
โข Using n & (n-1) to count set bits
โข Precomputing primes (since max set bits โค 20)
โข Avoiding repeated prime checks
Key insight: We check if the count of 1s is prime, not the number itself ๐ฅ
#LeetCode#DSA
Solved LeetCode 442 โ Find All Duplicates in an Array ๐
Used index marking trick (value โ index mapping).
If nums[abs(x)-1] is negative โ duplicate found.
โฑ O(n) time
๐ฆ O(1) space
In-place hashing is powerful ๐ฅ
#LeetCode#DSA#CodingInterview#Cpp
Solved Reverse Bits (LeetCode 190) ๐ฅ
Used pure bit manipulation (no strings ๐ซ).
Shift left โ extract last bit โ build reversed number in O(1) time & O(1) space.
Clean, optimal & interview-friendly approach ๐ช
#LeetCode#DSA#BitManipulation#100DaysOfCode
Solved LeetCode 67 โ Add Binary โ
Binary addition from right to left with carry handling.
Simple logic, clean implementation.
Time Complexity: O(n)
Space Complexity: O(1)
#LeetCode#DSA#Coding#CPP#100DaysOfCode