<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Dsa on Vijay Pagare</title><link>/blog/dsa/</link><description>Recent content in Dsa on Vijay Pagare</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sun, 12 Apr 2026 00:21:44 +0530</lastBuildDate><atom:link href="/blog/dsa/index.xml" rel="self" type="application/rss+xml"/><item><title>The Pattern Behind Kadane's Algorithm</title><link>/kadanes-algorithm-pattern/</link><pubDate>Sun, 12 Apr 2026 00:04:00 +0530</pubDate><guid>/kadanes-algorithm-pattern/</guid><description>&lt;p>Kadane’s Algorithm is a classic dynamic programming technique used to find the Maximum Subarray Sum within a one-dimensional array of numbers. It’s famous for its efficiency, turning what could be a brute-force $O(N^2)$ problem into a sleek $O(N)$ linear scan.&lt;/p>
&lt;hr>
&lt;h2 id="1-what-is-kadanes-algorithm">1. What is Kadane’s Algorithm?&lt;/h2>
&lt;p>The algorithm iterates through an array, keeping track of the maximum sum ending at the current position. It makes a simple choice at every element:&lt;/p></description></item><item><title>DSA - 2 new, 1 revision (Greedy, Kadane, Linked List)</title><link>/diary/dsa-11-apr/</link><pubDate>Sat, 11 Apr 2026 23:24:56 +0530</pubDate><guid>/diary/dsa-11-apr/</guid><description>&lt;h3 id="new-problems">New Problems&lt;/h3>
&lt;p>&lt;strong>435. Non-overlapping Intervals&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Concept:&lt;/strong> Greedy&lt;/li>
&lt;li>&lt;strong>Insight:&lt;/strong>&lt;br>
Sort intervals based on start. Iterate and compare adjacent intervals while maintaining &lt;code>prevEnd&lt;/code>.
&lt;ul>
&lt;li>If no overlap → update &lt;code>prevEnd&lt;/code>&lt;/li>
&lt;li>If overlap → increment count and update &lt;code>prevEnd = min(prevEnd, currEnd)&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Comment:&lt;/strong>&lt;br>
Solved partial conditions independently. Needed a hint to unlock the core greedy idea, then implemented successfully.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;strong>53. Maximum Subarray&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Concept:&lt;/strong> Kadane’s Algorithm&lt;/li>
&lt;li>&lt;strong>Insight:&lt;/strong>&lt;br>
At each step, track max of:
&lt;ul>
&lt;li>current element&lt;/li>
&lt;li>sum till now + current&lt;br>
Maintain a global maximum.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Comment:&lt;/strong>&lt;br>
Recognized the pattern after hint. Execution was straightforward once direction was clear.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="revision">Revision&lt;/h3>
&lt;p>&lt;strong>23. Merge K Sorted Lists&lt;/strong>&lt;/p></description></item><item><title>DSA - 1 new, 2 revision (Hashing, Linked List, Strings)</title><link>/diary/dsa-10-apr/</link><pubDate>Fri, 10 Apr 2026 21:00:00 +0530</pubDate><guid>/diary/dsa-10-apr/</guid><description>&lt;h3 id="-todays-progress">📌 Today’s Progress&lt;/h3>
&lt;p>&lt;strong>1 New • 2 Revisions&lt;/strong>&lt;/p>
&lt;hr>
&lt;h3 id="new-problem">New Problem&lt;/h3>
&lt;p>&lt;strong>49. Group Anagrams&lt;/strong>&lt;br>
&lt;strong>Insight:&lt;/strong> Sort characters of each word and use it as a key in a hashmap to group anagrams.&lt;br>
&lt;strong>Comment:&lt;/strong> Easy overall, but needed a hint to recall the sorting trick.&lt;/p>
&lt;p>&lt;strong>Observation (JS Quirk):&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>arr.sort()&lt;/code> sorts alphabetically (case-sensitive) by default&lt;/li>
&lt;li>For numbers → &lt;code>(a, b) =&amp;gt; a - b&lt;/code> works&lt;/li>
&lt;li>For alphabets → direct sort works, comparator logic differs&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="revisions">Revisions&lt;/h3>
&lt;p>&lt;strong>21. Merge Two Sorted Lists&lt;/strong>&lt;br>
&lt;strong>Insight:&lt;/strong>&lt;br>
Used standard linked list template:&lt;/p></description></item><item><title>DSA - 1 new, 3 revision (Matrix, DFS, Sliding Window, Binary Search)</title><link>/diary/dsa-9-apr/</link><pubDate>Thu, 09 Apr 2026 20:18:55 +0530</pubDate><guid>/diary/dsa-9-apr/</guid><description>&lt;p>Tackled a mix of new challenges and critical revisions, focusing on the philosophy that core patterns—Arrays, Strings, and DFS—must become second nature.&lt;/p>
&lt;hr>
&lt;h3 id="48-rotate-image-medium">48. Rotate Image (Medium)&lt;/h3>
&lt;h4 id="approach">Approach&lt;/h4>
&lt;ol>
&lt;li>&lt;strong>Transpose matrix&lt;/strong> → swap &lt;code>(i, j)&lt;/code> with &lt;code>(j, i)&lt;/code>&lt;/li>
&lt;li>&lt;strong>Reverse each row&lt;/strong>&lt;/li>
&lt;/ol>
&lt;h4 id="reflection">Reflection&lt;/h4>
&lt;ul>
&lt;li>Came up with a &lt;strong>half-baked approach&lt;/strong>&lt;/li>
&lt;li>Missed the &lt;strong>transpose + reverse pattern&lt;/strong>&lt;/li>
&lt;li>Made &lt;strong>silly mistakes&lt;/strong>:
&lt;ul>
&lt;li>Incorrect transpose logic (didn&amp;rsquo;t limit swaps correctly)&lt;/li>
&lt;li>Reverse logic not optimized (can use 2-pointer technique → O(n))&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Need to &lt;strong>slow down and think clearly before coding&lt;/strong>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="revisions">Revisions&lt;/h2>
&lt;h3 id="297-serialize-and-deserialize-binary-tree-hard">297. Serialize and Deserialize Binary Tree (Hard)&lt;/h3>
&lt;h4 id="approach-1">Approach&lt;/h4>
&lt;ul>
&lt;li>Use &lt;strong>DFS traversal&lt;/strong>&lt;/li>
&lt;li>Serialize:
&lt;ul>
&lt;li>Store values using delimiter &lt;code>&amp;quot;,&amp;quot;&lt;/code>&lt;/li>
&lt;li>Use &lt;code>&amp;quot;N&amp;quot;&lt;/code> for null nodes&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Deserialize:
&lt;ul>
&lt;li>Rebuild using DFS&lt;/li>
&lt;li>Maintain pointer/index across recursion&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="reflection-1">Reflection&lt;/h4>
&lt;ul>
&lt;li>Solved in &lt;strong>&amp;lt;25 mins&lt;/strong>&lt;/li>
&lt;li>Minor confusion:
&lt;ul>
&lt;li>Pointer increment in deserialization&lt;/li>
&lt;li>Must pass pointer &lt;strong>by reference&lt;/strong>&lt;/li>
&lt;li>Avoid loops; rely purely on DFS flow&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="3-longest-substring-without-repeating-characters-medium">3. Longest Substring Without Repeating Characters (Medium)&lt;/h3>
&lt;h4 id="approach-2">Approach&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>Sliding Window + Two Pointers&lt;/strong>
&lt;ul>
&lt;li>Expand window when valid&lt;/li>
&lt;li>Shrink when duplicate found&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Use &lt;strong>Set / HashMap&lt;/strong> for tracking characters&lt;/li>
&lt;/ul>
&lt;h4 id="reflection-2">Reflection&lt;/h4>
&lt;ul>
&lt;li>Felt &lt;strong>easy this time&lt;/strong>&lt;/li>
&lt;li>Stayed calm and executed step-by-step&lt;/li>
&lt;li>No unnecessary panic → big improvement&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="33-search-in-rotated-sorted-array-medium">33. Search in Rotated Sorted Array (Medium)&lt;/h3>
&lt;h4 id="approach-3">Approach&lt;/h4>
&lt;ul>
&lt;li>Modified &lt;strong>Binary Search&lt;/strong>&lt;/li>
&lt;li>Identify &lt;strong>sorted half&lt;/strong> and move accordingly&lt;/li>
&lt;/ul>
&lt;h4 id="reflection-3">Reflection&lt;/h4>
&lt;ul>
&lt;li>Took time to internalize &lt;strong>edge/else cases&lt;/strong>&lt;/li>
&lt;li>Once understood → logic felt clear&lt;/li>
&lt;li>Key idea: &lt;em>always move towards the sorted side&lt;/em>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="-insights--learnings">🧩 Insights / Learnings&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Core topics must become &lt;strong>muscle memory&lt;/strong>:&lt;/p></description></item><item><title>DSA: 1 new, 2 revision (DP, Backtracking, Graph)</title><link>/diary/dsa-daily-log-2026-04-08/</link><pubDate>Wed, 08 Apr 2026 21:02:17 +0530</pubDate><guid>/diary/dsa-daily-log-2026-04-08/</guid><description>&lt;p>Today’s session was a mix of one new challenge and two deep-dive revisions. The focus remains on identifying the &amp;ldquo;core pattern&amp;rdquo; rather than just memorizing the syntax.&lt;/p>
&lt;hr>
&lt;h2 id="new-challenge-300-longest-increasing-subsequence">New Challenge: 300. Longest Increasing Subsequence&lt;/h2>
&lt;p>&lt;strong>The Insight:&lt;/strong> The key here is building a &lt;code>dp&lt;/code> array where &lt;code>dp[i]&lt;/code> represents the length of the longest increasing subsequence ending at index &lt;code>i&lt;/code>.&lt;/p>
&lt;p>&lt;strong>The Process:&lt;/strong> To find &lt;code>dp[i]&lt;/code>, we look back at all elements &lt;code>j&lt;/code> (where &lt;code>j &amp;lt; i&lt;/code>). If &lt;code>nums[i] &amp;gt; nums[j]&lt;/code>, then &lt;code>nums[i]&lt;/code> can extend the subsequence ending at &lt;code>j&lt;/code>. The recurrence relation becomes:&lt;br>
&lt;code>dp[i] = max(dp[i], dp[j] + 1)&lt;/code>.&lt;/p></description></item><item><title>DSA: 1 new, 3 revision (Sliding Window, DP, LL, Graph)</title><link>/diary/dsa-daily-log-2026-04-07/</link><pubDate>Tue, 07 Apr 2026 23:38:42 +0530</pubDate><guid>/diary/dsa-daily-log-2026-04-07/</guid><description>&lt;p>Today was about strengthening the foundations and reflecting upon the mastery strategy. While the original plan was two new problems daily, the reality of high-level prep is teaching me that &lt;strong>revision and depth&lt;/strong> often outweigh raw volume.&lt;/p>
&lt;h2 id="-dsa-summary">🧠 DSA Summary&lt;/h2>
&lt;h3 id="1-longest-repeating-character-replacement-lc-424">1. Longest Repeating Character Replacement (LC 424)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>The Pivot:&lt;/strong> Shifting from a Brute Force approach (checking every possible substring) to a refined &lt;strong>Sliding Window&lt;/strong>.&lt;/li>
&lt;li>&lt;strong>The Insight:&lt;/strong> The window is valid as long as the number of replacements needed doesn&amp;rsquo;t exceed &lt;code>k&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Core Logic:&lt;/strong> &lt;code>Window Length - Max Frequency of a Character &amp;lt;= k&lt;/code>&lt;/li>
&lt;li>&lt;strong>Reflection:&lt;/strong> I managed to hack together a partial solution, but the &amp;ldquo;aha!&amp;rdquo; moment came from maintaining the character count hash to dynamically expand the right pointer and shrink the left. Though an even better solution with keep count of maxFrequency exists.&lt;/li>
&lt;/ul>
&lt;h3 id="2-pacific-atlantic-water-flow-lc-417">2. Pacific Atlantic Water Flow (LC 417)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>The Insight:&lt;/strong> Treat the 2D matrix as a graph. The key is defining a solid base condition: boundaries + visited sets + the &amp;ldquo;main business logic&amp;rdquo; (water height). Working backward from the oceans often simplifies the flow.&lt;/li>
&lt;/ul>
&lt;h3 id="3-remove-nth-node-from-end-of-list-lc-19">3. Remove Nth Node From End of List (LC 19)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>The Insight:&lt;/strong> The &amp;ldquo;Two-Pointer Gap&amp;rdquo; strategy. By advancing the first pointer &lt;code>n&lt;/code> steps ahead and then pointing the second to the head, they can hop together. When the first hits the end, the second points exactly to the node that needs removal. &lt;strong>One pass, &lt;code>O(n)&lt;/code> efficiency.&lt;/strong>&lt;/li>
&lt;/ul>
&lt;h3 id="4-maximum-product-subarray-lc-152">4. Maximum Product Subarray (LC 152)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>The Insight:&lt;/strong> Negative numbers are the wildcards—they can turn a minimum into a maximum instantly.&lt;/li>
&lt;li>&lt;strong>The Fix:&lt;/strong> It is vital to track &lt;strong>both&lt;/strong> the current min and max. When introducing a new element, consider three cases:
&lt;ol>
&lt;li>Starting a new subarray.&lt;/li>
&lt;li>Multiplying with the previous max.&lt;/li>
&lt;li>Multiplying with the previous min.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>&lt;strong>Note:&lt;/strong> Encountering a zero resets the running product.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="-strategy-shift-quality--quantity">🏗️ Strategy Shift: Quality &amp;gt; Quantity&lt;/h2>
&lt;p>I couldn&amp;rsquo;t accommodate a System Design (SD) question today due to time constraints, which sparked a realization about ROI (Return on Investment). Moving forward, I’m adjusting the daily goal:&lt;/p></description></item></channel></rss>