SGSiddharth Gandhiinsids-dsa-journal.hashnode.dev·Jul 26, 2025 · 4 min readDay 19 – Recursion, Backtracking, and Math Logic1. Subset Sum (Leetcode 78: Subsets) Problem: Return all possible subsets (the power set) of a given array of distinct integers. Intuition: At each index, we have two choices: include or exclude the current element. void solve(int i, vector<int>& num...00
SGSiddharth Gandhiinsids-dsa-journal.hashnode.dev·Jul 22, 2025 · 4 min readDay 18 – Greedy Algorithms1. N Meetings in One Room Problem: Given start[] and end[] times of meetings, find the maximum number of meetings that can be held in one room where only one meeting can happen at a time. Intuition: Sort meetings by end time. Always pick the meeting ...00
SGSiddharth Gandhiinsids-dsa-journal.hashnode.dev·Jul 21, 2025 · 6 min readDay 17 – Advanced Linked Lists + Trapping RainwaterLeetcode 237. Delete Node in a Linked List Intuition: You’re given access to the node itself, not the head. Copy data from next node, then delete the next node. void deleteNode(ListNode* node) { node->val = node->next->val; node->next = node-...00
SGSiddharth Gandhiinsids-dsa-journal.hashnode.dev·Jul 21, 2025 · 4 min readDay 16 – Linked List Insertions, Reversal, Midpoint, Merge, Nth Deletion, and AdditionInsert Node at Head Intuition: Create a new node, point it to the current head, and update the head. Node* insertAtHead(Node* head, int val) { Node* newNode = new Node(val); newNode->next = head; return newNode; } // TC: O(1) // SC: O(1) ...00
SGSiddharth Gandhiinsids-dsa-journal.hashnode.dev·Jul 20, 2025 · 5 min readDay 15 – Unique Paths, Reverse Pairs, Longest Substring Without Repeating Characters, and Starting Linked ListsLeetcode 62 – Unique Paths Problem: From top-left of an m x n grid, reach the bottom-right using only right/down moves. 1. Brute Force (Recursion) Intuition: Try all paths recursively. int count(int i, int j, int m, int n) { if (i >= m || j >= n...00