<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by VIGNESH  on Medium]]></title>
        <description><![CDATA[Stories by VIGNESH  on Medium]]></description>
        <link>https://medium.com/@vignesh_22659?source=rss-11043e3e70db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by VIGNESH  on Medium</title>
            <link>https://medium.com/@vignesh_22659?source=rss-11043e3e70db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:44:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vignesh_22659/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dynamic Array: Understanding the Problem Before Writing Code]]></title>
            <link>https://medium.com/@vignesh_22659/dynamic-array-understanding-the-problem-before-writing-code-bc72f5da7225?source=rss-11043e3e70db------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc72f5da7225</guid>
            <category><![CDATA[dynamic-array]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[java-arraylist]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[VIGNESH ]]></dc:creator>
            <pubDate>Sat, 12 Sep 2026 09:35:47 GMT</pubDate>
            <atom:updated>2026-09-12T09:35:47.225Z</atom:updated>
            <content:encoded><![CDATA[<h3>What HackerRank’s “Dynamic Array” Problem Actually Taught Me</h3><p>When I opened the Dynamic Array problem on HackerRank, I expected the usual — read the constraints, write some Java, submit. But this one didn’t fight me on the coding side. It fought me on the <em>story</em>.</p><p>I sat there re-reading the problem statement for longer than I’d like to admit, not because the syntax was hard, but because I genuinely didn’t understand what was being asked.</p><h3>Where I Actually Got Stuck</h3><p>Here’s the honest list of things that confused me, in the order I hit them:</p><ul><li>What are these two query types even supposed to represent?</li><li>In 1 x y and 2 x y — what <em>is</em> x? What <em>is</em> y? The problem throws these letters around like I should already know.</li><li>Why does the formula keep dragging in this lastAnswer thing and XOR-ing it with x?</li><li>And once I saw (x ^ lastAnswer), where on earth did the % n come from?</li></ul><p>None of this was a Java problem. It was a <em>translation</em> problem — I hadn’t converted the words into operations yet.</p><p>The part that really unlocked it for me was realizing y doesn&#39;t mean the same thing in both queries:</p><ul><li>In a type 1 query, y is the value you&#39;re adding.</li><li>In a type 2 query, y is used to pick <em>which</em> element you want out of the array you land on.</li></ul><p>Same letter, two completely different jobs depending on context. Once that clicked, the rest of the problem stopped feeling like a wall of symbols.</p><p>The other piece that took me a minute was this: lastAnswer isn&#39;t just some leftover variable sitting in the corner — it changes after <em>every</em> type 2 query, and because it changes, the <em>same</em> x can point to a completely different array the next time you use it. That&#39;s the whole trap of the problem. You can&#39;t just compute an index once and reuse your intuition; you have to actually track state.</p><h3>The Mental Model That Finally Made Sense</h3><p>After going back and forth on this, here’s the model I landed on:</p><pre>1 x y<br>→ find an array<br>→ add y</pre><pre>2 x y<br>→ find an array<br>→ get an element using y<br>→ update lastAnswer</pre><p>And the array itself is always chosen the same way, regardless of query type:</p><pre>idx = (x ^ lastAnswer) % n</pre><p>Once I had it framed this way — as “find the array, then do one of two things to it” — writing the actual Java became almost boring in comparison:</p><pre>public static List&lt;Integer&gt; dynamicArray(int n, List&lt;List&lt;Integer&gt;&gt; queries) {<br>    ArrayList&lt;ArrayList&lt;Integer&gt;&gt; arr = new ArrayList&lt;&gt;();<br>    int lastAnswer = 0;<br>    ArrayList&lt;Integer&gt; answers = new ArrayList&lt;&gt;();<br><br>    for (int i = 0; i &lt; n; i++) {<br>        arr.add(new ArrayList&lt;Integer&gt;());<br>    }<br><br>    for (List&lt;Integer&gt; query : queries) {<br>        if (query.get(0) == 1) {<br>            int idx = (query.get(1) ^ lastAnswer) % n;<br>            arr.get(idx).add(query.get(2));<br>        } else if (query.get(0) == 2) {<br>            int idx = (query.get(1) ^ lastAnswer) % n;<br>            lastAnswer = arr.get(idx).get(query.get(2) % arr.get(idx).size());<br>            answers.add(lastAnswer);<br>        }<br>    }<br><br>    return answers;<br>}</pre><p>I traced through the sample input by hand before trusting this — n = 2 with queries 1 0 5, 1 1 7, 1 0 3, 2 1 0, 2 1 1 — and watching lastAnswer flip from 0 to 7 mid-way through, which then changed which array the last query pointed to, is what actually convinced me the formula was right. The final answers came out as 7 and 3, matching what HackerRank expected.</p><h3>The Real Lesson Here</h3><p>Looking back, I wasn’t actually struggling with arrays or with Java. I was struggling to turn a story-based problem statement into a set of plain operations.</p><p>That’s made me change how I approach these DSA problems now. Before writing a single line of code, I try to answer four questions first:</p><ol><li>What data do I actually have?</li><li>What operations can happen to it?</li><li>What does each input value mean?</li><li>What am I supposed to output at the end?</li></ol><p>Only after I can answer all four do I let myself start coding.</p><p>It sounds obvious written out like that. But it took getting genuinely stuck on a “simple” array problem for me to actually internalize it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc72f5da7225" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>