programmer / maki zenin paglu

Joined May 2025
762 Photos and videos
Pinned Tweet
Apr 24
tough times dont last, but tough people do.
1
15
2,572
premium is over. so from now on i won't post #SDESheetChallenge solutionsπŸ₯€
1
13
Day 14 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 2: Remove Duplicates from Sorted Array Approach- -> Use two pointers: i and j. -> i tracks the position of the last unique element. -> j scans the array for new unique elements. -> If nums[j] is different from nums[i]: - Place it at position i 1. - Increment i. -> Continue until the end of the array. # Key Idea- Since the array is already sorted, all duplicates are adjacent. Two pointers help keep only the unique elements in-place. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
3
6
132
Day 14 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 3: Max Consecutive Ones Approach- -> Traverse the array while maintaining the current streak of 1s. -> If the current element is 1, increment the streak length. -> If the current element is 0: - Update the maximum streak length. - Reset the current streak to 0. -> After traversal, update the answer one final time. # Key Idea- Keep track of the length of the current sequence of consecutive 1s and continuously update the maximum length found so far. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
2
6
53
Day 14 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 1: Trapping Rain Water Approach- -> Initialize two pointers: left and right. -> Maintain leftMax and rightMax to track the highest bars seen so far. -> If height[left] <= height[right]: - Update leftMax if needed. - Otherwise, add leftMax - height[left] to the answer. - Move left forward. -> Otherwise: - Update rightMax if needed. - Otherwise, add rightMax - height[right] to the answer. - Move right backward. # Key Idea- The amount of water trapped at a position depends on the smaller of the maximum heights on its left and right. Two pointers allow this to be computed in a single pass. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
2
7
195
Jun 14
it's been a month since i last touched caffeine. when i started, i thought i'd sleep better, have more energy, and feel more consistent throughout the day. the reality has been a little different. yes, i sleep much better now. but i also seem to enjoy sleeping a little too much. and somehow, i still feel sleepy throughout most of the day. so after a month without caffeine, my biggest takeaway is that i probably won't be giving it up.
16
221
Jun 13
Day 13 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 1: Rotate List Approach- -> Find the length of the linked list. -> Compute k = k % length. -> Connect the last node to the head, forming a circular linked list. -> Move to the (length - k)th node. -> Break the circle and make the next node the new head. # Key Idea- Instead of rotating the list one step at a time, convert it into a circular list and directly locate the new head. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
2
10
235
Jun 13
Day 13 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 2: Copy List with Random Pointer Approach- -> Insert a copy node after every original node. -> Assign random pointers for the copied nodes using: original->random->next. -> Separate the copied list from the original list. -> Restore the original list while extracting the cloned list. # Key Idea- By placing each copied node right next to its original node, random pointers can be assigned without using extra space. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
1
4
157
Jun 13
Day 13 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 3: 3Sum Approach- -> Sort the array. -> Fix one element at a time. -> Use two pointers (left and right) on the remaining part of the array. -> If the sum is less than 0, move left forward. -> If the sum is greater than 0, move right backward. -> If the sum is 0, store the triplet and skip duplicates. # Key Idea- After sorting, the two-pointer technique efficiently finds pairs that complete the target sum while avoiding duplicate triplets. Time Complexity: O(nΒ²) Space Complexity: O(1) (excluding the output array) #DSA #LeetCode #SDESheet #Cpp
4
99
Jun 13
Just woke up from a 5 hour nap. Time to lock in.
5
20
800
Jun 12
Day 12 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 1: Palindrome Linked List Approach -> Find the middle of the linked list using slow and fast pointers. -> Split the list into two halves. -> Reverse the second half. -> Compare both halves node by node. -> If all corresponding nodes match, the linked list is a palindrome. # Key Idea A palindrome reads the same forwards and backwards. By reversing the second half, we can compare both halves directly in O(n) time. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
3
16
331
Jun 12
Day 12 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 2: Linked List Cycle II Approach -> Use slow and fast pointers to detect a cycle. -> If the pointers never meet, return NULL. -> Once they meet, move slow back to the head. -> Move both pointers one step at a time. -> The node where they meet again is the starting node of the cycle. # Key Idea After the first meeting point inside the cycle, resetting one pointer to the head and moving both pointers at the same speed leads them to the cycle's starting node. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
1
7
132
Jun 12
Day 12 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 3: Flattening a Linked List Approach -> Recursively flatten the linked list on the right. -> Merge the current list with the already flattened list. -> Use a merge function similar to merging two sorted linked lists. -> Connect nodes using the bottom pointer and discard next links. # Key Idea Flatten the list from right to left and keep merging sorted bottom lists until a single sorted linked list is obtained. Time Complexity: O(N Γ— M) Space Complexity: O(N) (Recursion Stack) #DSA #LeetCode #SDESheet #Cpp
4
73
Jun 11
Day 11 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 1: Intersection of Two Linked Lists Approach- -> Traverse both lists simultaneously. -> When a pointer reaches NULL, move it to the head of the other list. -> The pointers will either meet at the intersection node or at NULL. # Key Idea- Both pointers travel the same total distance (A B), which aligns them at the intersection point. Time Complexity: O(n m) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
2
11
217
Jun 11
Day 11 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 2: Linked List Cycle Approach- Use two pointers: slow and fast. -> Move slow by 1 step and fast by 2 steps. -> If fast reaches NULL, no cycle exists. -> If slow and fast meet at any point, a cycle exists. # Key Idea In a cyclic linked list, the fast pointer will eventually catch up to the slow pointer. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
1
5
126
Jun 11
Day 11 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 3: Reverse Nodes in k-Group Approach- -> Check if at least k nodes are available. -> Reverse the first k nodes using the standard linked list reversal technique. -> Recursively process the remaining list. -> Connect the last node of the reversed group to the head of the next processed group. # Key Idea Reverse the linked list in chunks of size k while keeping the remaining nodes connected. If fewer than k nodes remain, leave them as they are. Time Complexity: O(n) Space Complexity: O(n/k) (Recursion Stack) #DSA #LeetCode #SDESheet #Cpp
6
57
Jun 11
such a bad day today.
2
10
129
Jun 11
guys im maki zenin.
1
8
292
Jun 10
Day 10 – #SDESheetChallenge @takeUforward_ @striver_79 (a thread 🧡) Problem 1: Remove Nth Node From End of List Approach: 1. Traverse the linked list and calculate its length. 2. If n equals the length of the list: - Remove the head node. - Return head->next. 3. Otherwise, find the node just before the one to be deleted. - Move to the (length - n)th node. 4. Adjust the links: - prev->next = prev->next->next 5. Return the head of the modified list. The key idea is that once the length of the list is known, the node to be removed can be located by converting its position from the end into a position from the beginning. Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
1
17
622
Jun 10
Day 10 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 2: Add Two Numbers Approach: 1. Create a dummy node to build the answer list. 2. Initialize: - carry = 0 - temp = dummy 3. Traverse both linked lists until: - l1 is exhausted - l2 is exhausted - carry becomes 0 4. For each iteration: - Add the current digits from l1 and l2 (if they exist). - Add the carry from the previous step. - Create a new node with: sum % 10 - Update: carry = sum / 10 5. Attach the new node to the answer list. 6. Continue until all digits and carry are processed. 7. Return: - dummy->next as the head of the resulting linked list. The key idea is to simulate elementary addition digit by digit, carrying over any value greater than 9 to the next position. Time Complexity: O(max(n, m)) Space Complexity: O(max(n, m)) #DSA #LeetCode #SDESheet #Cpp
1
10
782
Jun 10
Day 10 – #SDESheetChallenge @takeUforward_ @striver_79 Problem 3: Delete Node in a Linked List Approach: 1. Copy the value of the next node into the current node. 2. Skip the next node by updating the link: - node->next = node->next->next 3. The current node now contains the value of the deleted node's successor, effectively removing the target node from the list. The key idea is that we are not given access to the head of the linked list. Instead of deleting the current node directly, we overwrite its value with the next node's value and bypass the next node. Time Complexity: O(1) Space Complexity: O(1) #DSA #LeetCode #SDESheet #Cpp
1
7
841