<?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 Aditya Ojha on Medium]]></title>
        <description><![CDATA[Stories by Aditya Ojha on Medium]]></description>
        <link>https://medium.com/@kaditya67?source=rss-f8ef5b2a3304------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Hfukqyw6efxRhK5LJK7bTA.jpeg</url>
            <title>Stories by Aditya Ojha on Medium</title>
            <link>https://medium.com/@kaditya67?source=rss-f8ef5b2a3304------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:39:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaditya67/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[Kadane’s Algorithm — “Should I Continue or Restart?”]]></title>
            <link>https://medium.com/@kaditya67/kadanes-algorithm-should-i-continue-or-restart-4c4ea560d629?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c4ea560d629</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Thu, 15 Oct 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-10-15T05:31:01.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wsLsY5oFt_rUSvjZPBA-hw.png" /><figcaption>Kadane Algorithm Problem</figcaption></figure><p>Suppose:</p><pre>arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]</pre><p>And the question is:</p><blockquote><strong><em>Find the contiguous(continuous) subarray with the maximum sum.</em></strong></blockquote><p>The answer is:</p><pre>[4, -1, 2, 1]<br>sum = 6</pre><h3>Brute force?</h3><p>We could generate every possible subarray:</p><pre>[-2]</pre><pre>[-2, 1]</pre><pre>[-2, 1, -3]</pre><pre>...</pre><pre>[4, -1, 2, 1]</pre><pre>...</pre><p>There are <strong>O(N²)</strong> possible subarrays.</p><p>And if we calculate each sum from scratch, it can become <strong>O(N³)</strong>.</p><p>Can we do better?</p><h3>Understand Kadane</h3><p>Let’s see what is Kadane and when we could apply it…</p><p>Imagine you’re walking through the array while carrying a running sum.</p><p>At every element, ask:</p><blockquote><strong><em>“Should I continue my current subarray, or would I be better off starting a new one here?”</em></strong></blockquote><p>That’s Kadane’s Algorithm.</p><blockquote>When can we ask such question?</blockquote><p>Only when we know</p><p>We’ll maintain:</p><pre>currentSum → best sum ending HERE<br>maxSum     → best sum we&#39;ve seen ANYWHERE</pre><p>A sweet example to give you whole gist of Kadane:</p><p>Start:</p><pre>arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]<br>currentSum = 0<br>maxSum = -∞</pre><h3>At -2</h3><pre>[-2]<br> ↑<br>current = -2<br>best = -2</pre><pre>currentSum = max(-2, 0 + -2)<br>            = -2<br>maxSum = -2</pre><h3>At 1</h3><p>Now we have a choice:</p><pre>Continue:</pre><pre>-2 + 1 = -1</pre><pre>OR</pre><pre>Start fresh:</pre><pre>1</pre><p>Which is better?</p><pre>max(-1, 1) = 1</pre><p>So:</p><pre>currentSum = 1<br>maxSum = 1</pre><p><strong>We throw away the </strong><strong>-2.</strong></p><p>That’s the key idea.</p><blockquote>Everything boils down to this:</blockquote><pre>currentSum = max(arr[i], currentSum + arr[i]);</pre><p>Read it as:</p><blockquote><strong><em>Should I start a new subarray at </em></strong><strong><em>arr[i], or continue the old one?</em></strong></blockquote><p>Then:</p><pre>maxSum = max(maxSum, currentSum);</pre><p>means:</p><blockquote><strong><em>Is this the best subarray I’ve seen so far?</em></strong></blockquote><h3>Kadane’s Code</h3><pre>int maxSubArray(vector&lt;int&gt;&amp; arr) {<br><br>    int currentSum = arr[0];<br>    int maxSum = arr[0];<br><br>    for (int i = 1; i &lt; arr.size(); i++) {<br><br>        currentSum = max(arr[i],<br>                         currentSum + arr[i]);<br><br>        maxSum = max(maxSum, currentSum);<br>    }<br><br>    return maxSum;<br>}</pre><p>That’s it, Super short and super easy but the magic it does is worth more!</p><h3>But WHY can we throw away the previous sum?</h3><p>This is the part you should really understand.</p><p>Suppose:</p><pre>currentSum = -5<br>arr[i] = 4      # Current Element</pre><p>We compare:</p><pre>Continue:<br>-5 + 4 = -1</pre><pre>Restart:<br>4</pre><pre>Choose 4</pre><p>The important thing is that <strong>-5 is hurting us</strong>.</p><p>But look at this:</p><pre>currentSum = 5<br>arr[i] = -3</pre><p>Should we restart?</p><pre>Continue:<br>5 + (-3) = 2</pre><pre>Restart:<br>-3</pre><p>Obviously:</p><pre>2 &gt; -3  # This check is done by max()</pre><p>So we <strong>continue</strong>.</p><p>Even though we just saw a negative number! ❌</p><p>Kadane Variants</p><pre>                Kadane<br>                  │<br>        ┌─────────┴─────────┐<br>        ↓                   ↓<br> Maximum Sum          Minimum Sum<br>        │<br>        ↓<br> Track Indices<br>        │<br>        ↓<br> Circular Array<br>        │<br>        ↓<br> Maximum Product</pre><p>Learn and solve it this way!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*NZ07jjqEp9CaEqPkpJm2Ow.png" /><figcaption>Variants of Kadane’s Algorithm</figcaption></figure><h3>How to Recognize Kadane’s Algorithm</h3><ol><li>Subarray optimization:<br>The problem asks for the maximum (or minimum) sum or product of a contiguous subarray.</li><li>Mixed positive and negative values:<br>The array contains both positive and negative values, making simple greedy or two-pointer techniques inapplicable.</li><li>Local restart choice:<br>The decision at every step simplifies to: <em>“append to current segment vs. start fresh at current element”</em>.</li></ol><p>Checkout my github for more details on <a href="https://github.com/Kaditya67/DSA/blob/learn/pattern/01-array/04-kadanes-algorithm/README.md"><em>Kadane’s Algorithm</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c4ea560d629" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prefix Sum — The “Don’t Calculate It Again” Trick]]></title>
            <link>https://medium.com/@kaditya67/prefix-sum-the-dont-calculate-it-again-trick-465d82e589d8?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/465d82e589d8</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-10-14T05:31:01.655Z</atom:updated>
            <content:encoded><![CDATA[<p>If Sliding Window is about <strong>moving a range</strong>, Prefix Sum is about:</p><blockquote><em>Doing the addition once, storing it, and reusing it.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T1_Rb_EprBxM8YTL" /><figcaption>Prefix Sum Example</figcaption></figure><p>Let’s understand with an example:</p><p>Suppose:</p><pre>arr = [2, 1, 3, 4, 5]</pre><p>And someone asks:</p><blockquote><em>What is the sum from index </em><em>1 to </em><em>3?</em></blockquote><p>That’s:</p><pre>[2, 1, 3, 4, 5]<br>    └──────┘<br>     1  3</pre><pre>1 + 3 + 4 = 8</pre><p>Easy.</p><p>But imagine they ask <strong>100,000 such questions</strong>.</p><p>You don’t want to repeatedly do:</p><pre>1 + 3 + 4<br>3 + 4<br>2 + 1 + 3 + 4<br>...</pre><p><strong>Prefix Sum comes to rescue.</strong></p><h3>Prefix Sum</h3><p>Create another array that remembers the sum <strong>up to every position</strong>.</p><p>Original:</p><pre>arr:<br>[ 2   1   3   4   5 ]<br>  0   1   2   3   4</pre><p>Prefix:</p><pre>prefix:<br>[ 2   3   6   10   15 ]<br>  0   1   2    3    4</pre><p>Because:</p><pre>prefix[0] = 2<br>prefix[1] = 2 + 1 = 3<br>prefix[2] = 2 + 1 + 3 = 6<br>prefix[3] = 2 + 1 + 3 + 4 = 10<br>prefix[4] = 2 + 1 + 3 + 4 + 5 = 15</pre><p>So:</p><blockquote><strong><em>prefix[i] = sum of everything from index </em></strong><strong><em>0 to </em></strong><strong><em>i.</em></strong></blockquote><p>That’s it. That’s the main idea.</p><h4>How it helps????</h4><p>Question:</p><blockquote><em>Sum from index </em><em>1 to </em><em>3?</em></blockquote><pre>arr:<br>[ 2 | 1  3  4 | 5 ]<br>      └──────┘</pre><p>We know:</p><pre>prefix[3] = 2 + 1 + 3 + 4<br>          = 10</pre><p>But we don’t want the 2.</p><p>And:</p><pre>prefix[0] = 2</pre><p>So:</p><pre>prefix[3] - prefix[0]</pre><pre>10 - 2</pre><pre>= 8 </pre><p>We just turned a potentially large calculation into:</p><pre>one subtraction</pre><h3>Formulas to use</h3><p>For a range: L → R</p><p>use:</p><pre>sum = prefix[R] - prefix[L - 1];</pre><p>Example:</p><pre>L = 1<br>R = 3<br>sum = prefix[3] - prefix[0]<br># 10 - 2 = 8</pre><h4>One special case</h4><p>If: L = 0</p><p>there’s nothing before it.</p><p>So:</p><pre>sum = prefix[R];</pre><h4>How fast?</h4><p>If there are Q queries:</p><pre>Without PrefixSum:<br>O(N × Q)</pre><pre>With PrefixSum:<br>O(N + Q)</pre><p><strong>“Now comes the really interesting pattern”</strong></p><p>Suppose:</p><pre>arr = [1, 2, 1, 2, 1]</pre><p>And ask:</p><blockquote><strong><em>How many subarrays have sum = 3?</em></strong></blockquote><p>Look at them:</p><pre>[1, 2]       = 3 ✅<br>[2, 1]       = 3 ✅<br>[1, 2]       = 3 ✅</pre><p>Answer: 3</p><p>Solve with — Prefix Sum + HashMap</p><p>Suppose current prefix sum is:</p><pre>currentSum = 7</pre><p>and we want:</p><pre>target = 3</pre><p>We ask:</p><pre>currentSum - target<br>7 - 3 = 4</pre><p>So:</p><blockquote><strong><em>Have we seen a previous prefix sum of </em></strong><strong><em>4?</em></strong></blockquote><p>If yes:</p><pre>previous prefix = 4<br>current prefix  = 7</pre><pre>7 - 4 = 3 </pre><p>Therefore, the elements between those two positions have sum 3.</p><p>That’s a beautiful pattern.</p><p>Another way to visualise:</p><pre>arr = [ ... | middle elements | ... ]<br>prefix before middle = 4<br>prefix after middle  = 7<br>                  7<br>                  ↓<br>[ ... |  a  b  c  | ... ]<br>      ↑<br>      4<br>7 - 4 = 3</pre><blockquote>Don’t memorize it yet.</blockquote><p>Think:</p><pre>Current prefix = 10<br>Target = 4</pre><pre>10 - 4 = 6</pre><pre>Have I seen prefix sum 6 before?</pre><pre>YES<br>    ↓<br>That middle portion must sum to 4 🎯</pre><h3>The 3 things to remember (CheatSheet)</h3><pre>1️⃣ prefix[i]<br>   = sum from 0 → i<br>2️⃣ range sum<br>   = prefix[R] - prefix[L-1]<br>3️⃣ subarray sum = K<br>   = Prefix Sum + HashMap</pre><h3>How to recognize Prefix Sum</h3><p>When you see:</p><blockquote><strong><em>“Find the sum between L and R.”</em></strong></blockquote><p>Think:</p><pre>               Range Sum?<br>                     ↓<br>              Many queries?<br>                     ↓<br>                PREFIX SUM</pre><p>And when you see:</p><blockquote><strong><em>“Count subarrays whose sum = K.”</em></strong></blockquote><p>Think:</p><pre>Subarray Sum = K<br>       ↓<br>Prefix Sum<br>       +<br>HashMap</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=465d82e589d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sliding Window]]></title>
            <link>https://medium.com/@kaditya67/sliding-window-5a50ad64f981?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a50ad64f981</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-10-13T05:31:01.502Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn Two Pointer Before this…</p><p>If <strong>Two Pointers</strong> are two fingers moving through an array, then:</p><blockquote><strong><em>Sliding Window = two pointers creating a continuous section of the array.</em></strong></blockquote><p>Imagine this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*dpnM40-cElyblRuM.png" /><figcaption>Sliding Window Problem</figcaption></figure><p>Why need sliding window?</p><p>Suppose:</p><pre>arr = [2, 1, 5, 1, 3, 2]<br>k = 3</pre><p>We want:</p><blockquote><strong><em>Maximum sum of any 3 consecutive numbers.</em></strong></blockquote><p>If you look at the problem,</p><p>[5,1,3] is of size 3 and gives sum as 9 which is greater than any other consecutive numbers whose sum is maximum.</p><p>Two Pointer moves both the pointers freely but in sliding window, we maintain a <strong>specific size</strong> and only find and maintain results from the window at the moment.</p><p>But why use Sliding window ?????</p><p>We could calculate every group:</p><pre>2 + 1 + 5 = 8<br>1 + 5 + 1 = 7<br>5 + 1 + 3 = 9  ← best<br>1 + 3 + 2 = 6</pre><p>In Sliding window:</p><p>When we move from:</p><pre>[2, 1, 5]</pre><p>to:</p><pre>[1, 5, 1]</pre><p>we didn’t need to calculate everything again.</p><p>We already know:</p><pre>2 + 1 + 5 = 8</pre><p>So:</p><pre>8<br>- 2    ← leaving<br>+ 1    ← entering<br>----<br>7</pre><p>In this example it seems like a very small change, but suppose we are working in Tree or Graph, we do call a recursive function and then sum like… recrFn(2)+recrFn(1)+recrFn(5) = 8</p><p>Using sliding window, we cut two recursive call and just need to call, recrFn(1)=1 and just calculate using the <strong>leaving Value</strong> and <strong>entering Value</strong> quickly.</p><blockquote>In short, this helps avoid repeatative calculation too.</blockquote><p>Sliding Window movement,</p><p>Start:</p><pre>[ 2   1   5   1   3   2 ]<br>  L           R<br>  └───────┘<br>    window</pre><pre>sum = 8</pre><p>Slide one step:</p><pre>[ 2   1   5   1   3   2 ]<br>      L           R<br>      └───────┘</pre><pre>sum = 8 - 2 + 1<br>    = 7</pre><p>Slide again:</p><pre>[ 2   1   5   1   3   2 ]<br>          L           R<br>          └───────┘</pre><pre>sum = 7 - 1 + 3<br>    = 9 🎯</pre><p>Slide again:</p><pre>[ 2   1   5   1   3   2 ]<br>              L           R<br>              └───────┘</pre><pre>sum = 9 - 5 + 2<br>    = 6</pre><p>Answer: 9</p><p>In Code,</p><pre>int windowSum = 0;<br>int maxSum = 0;<br><br>// First window<br>for (int i = 0; i &lt; k; i++) {<br>    windowSum += arr[i];<br>}<br><br>maxSum = windowSum;<br><br>// Slide the window<br>for (int right = k; right &lt; arr.size(); right++) {<br><br>    windowSum += arr[right];       // new element enters<br>    windowSum -= arr[right - k];   // old element leaves<br><br>    maxSum = max(maxSum, windowSum);<br>}</pre><p>Why faster??</p><pre>Calculate every window from scratch<br><br>[2 1 5] → 3 operations<br>[1 5 1] → 3 operations<br>[5 1 3] → 3 operations<br>[1 3 2] → 3 operations<br><br>≈ O(N × K)</pre><p>Sliding Window:</p><pre>Calculate first window → K<br><br>Then every next window:<br>remove 1<br>add 1<br><br>≈ O(N)</pre><p>Patterns of Sliding Window:</p><h3>1. Fixed-size window</h3><p>The window size is given.</p><p>Example:</p><blockquote><em>Find the maximum sum of </em><strong><em>K</em></strong><em> consecutive elements.</em></blockquote><p>k=3</p><pre>[ 2  1  5  1  3  2 ]<br>  └─────┘<br>    size 3</pre><pre>      └──────┘<br>        size 3</pre><pre>           └──────┘<br>            size 3</pre><p>The window <strong>always stays size 3</strong>.</p><h3>2. Variable-size window</h3><p>This is where Sliding Window becomes really powerful.</p><p>Instead of:</p><blockquote><em>“Give me exactly 3 elements.”</em></blockquote><p>we might ask:</p><blockquote><strong><em>“Find the longest subarray whose sum ≤ 7.”</em></strong></blockquote><p>Now the window can grow and shrink.</p><p>Example:</p><pre>arr = [2, 1, 3, 2, 1]</pre><p>Start:</p><pre>[ 2 ]<br> ↑<br> L/R</pre><pre>sum = 2</pre><p>Expand:</p><pre>[ 2  1 ]<br> ↑     ↑<br> L     R</pre><pre>sum = 3</pre><p>Expand:</p><pre>[ 2  1  3 ]<br> ↑        ↑</pre><pre>sum = 6</pre><p>Expand:</p><pre>[ 2  1  3  2 ]<br> ↑           ↑</pre><pre>sum = 8 ❌</pre><p>Too large!</p><p>So we <strong>shrink from the left</strong>.</p><pre>[ 2  1  3  2 ]<br> ↑           ↑<br> L           R</pre><pre>remove 2</pre><pre>[ 1  3  2 ]<br> ↑        ↑</pre><pre>sum = 6 ✅</pre><p>Then continue expanding.</p><p>This gives us the core variable-window pattern:</p><pre>right → expand<br>if condition becomes invalid:<br>left → shrink</pre><p>Template</p><pre>int left = 0;<br>int sum = 0;<br><br>for (int right = 0; right &lt; n; right++) {<br><br>    // Expand<br>    sum += arr[right];<br><br>    // Window is invalid → shrink<br>    while (sum &gt; target) {<br>        sum -= arr[left];<br>        left++;<br>    }<br><br>    // Current window is valid<br>    // [left ... right]<br>}</pre><p>Important to Note:</p><p><strong>The Rule</strong>: If an array contains negative numbers and asks for subarray sum targets, Sliding Window fails. Use Prefix Sum + HashMap instead.</p><p>Checkout my github for more <a href="https://github.com/Kaditya67/DSA/blob/learn/pattern/01-array/02-sliding-window/README.md">Sliding Window</a> details.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a50ad64f981" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA: Two Pointer - learn the pattern]]></title>
            <link>https://medium.com/@kaditya67/dsa-two-pointer-learn-the-pattern-935772400b30?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/935772400b30</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-10-12T05:31:01.522Z</atom:updated>
            <content:encoded><![CDATA[<h3>Two Pointer</h3><p>Think of <strong>two pointers as two fingers moving through an array</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*saEqtj3lwBCyAyub" /><figcaption>Two Pointer Approach</figcaption></figure><p>Quick summary:</p><p>Instead of repeatedly checking <strong>every pair</strong>, we keep track of <strong>two positions</strong></p><p>Then we ask:</p><blockquote><strong><em>“Based on what I just saw, which pointer should move?”</em></strong></blockquote><h3>Nothing beats a perfect example!</h3><p>Find 2 numbers whose sum = 7</p><pre>[1, 2, 3, 4, 5, 6]</pre><p>We can tell very easily, 2+5 = 7</p><p>But to find this, we often write a O(N²) loop</p><pre>for i in range(n):              # N times<br>    for j in range(i + 1, n):    # N times<br>        if A[i] + A[j] == target:<br>            return (i, j)</pre><p>If <strong>Array is sorted</strong>,</p><p>This could be done very smartly and in a faster way, we could keep track of one point at a time and just move the other one to find the result faster.</p><p>Let’s think how!</p><p>For now, let’s keep both the pointers Left(L) and Right (R) on opposite ends and start the loop:<br>L=0 and R=5 and we need sum to be 9</p><p>A[L] = 1 and A[R]=6, let see the sum of them — 1+6=7</p><p>sum &lt; 9, so we can just increase our left side to get more higher value i.e 2</p><p>2+6=8, still &lt; 9</p><p>Increase more, 3+6=9, we got the perfect match, in this sitution we just moved 3 steps to get the result.</p><p>Let’s compare with out older appraoch, when we had O(N²)</p><p>we would have start with L=0 and R=0</p><p>Getting A[L]=1 and Also A[R]=1, 1+1=2</p><p>We move R till the end for each i iteration and check the value for each L<br>like… 1+2=3, 1+4=5, 1+6=7</p><p>for i=2 and j=5, we would have got the result taking… 10 steps</p><p>This makes for N outer iteration we get N inner iteration for each N, which makes the complexity O(N²)</p><p>What is Two Pointer Approach?</p><p>In a sorted Array, to get a higher value we need to <strong>move Right ( from the Left side i.e L++ ) </strong>and to reduce our sum we need to <strong>move Left</strong> ( from the Right side i.e R — — )</p><p>Sum = left + right</p><p>When:</p><pre>If sum &lt; target:<br>    We need a bigger number<br>    → move L forward<br>    → L++</pre><p>we need something bigger → move from <strong>Left Side, L++</strong></p><p>When:</p><pre>If sum &gt; target:<br>    We need a smaller number<br>    → move R backward<br>    → R--</pre><p>we know we need something smaller → move from <strong>Right Side, R — —</strong></p><p>We can use this same Two Pointer in different way — We can call them patterns</p><p>1. Opposite-direction pointers (This is what we Saw!)</p><p>Pointers start at <strong>both ends</strong>.</p><pre>[ 1  2  4  7  11  15 ]<br>  ↑                 ↑<br> left              right</pre><pre>       →       ←</pre><p>They move <strong>towards each other</strong>.</p><p>Common problems:</p><ul><li>Two Sum on sorted array</li><li>3Sum</li><li>Palindrome</li><li>Container With Most Water</li><li>Pair with target difference</li></ul><h3>Mental picture</h3><blockquote><strong><em>“Start from both ends and squeeze inward.”</em></strong></blockquote><p>2. Same-direction pointers</p><p>Both pointers move →</p><pre>[ 1  1  2  2  3  3  4 ]<br>  ↑ ↑<br>  L R</pre><pre>    → →</pre><p>This is extremely common for:</p><ul><li>Removing duplicates</li><li>Sliding window</li><li>Longest/shortest subarray</li><li>Substring problems</li><li>Partitioning</li></ul><p>Think:</p><blockquote><strong><em>“One pointer explores, the other maintains the valid region.”</em></strong></blockquote><p>Use Two pointer:</p><ol><li>Is the array/string sorted?<br> ↓<br>2. Am I looking for a pair?<br> ↓<br>3. Can one pointer move based on<br> what the other pointer tells me?<br> ↓<br>4. Can I avoid revisiting elements?<br> ↓<br> Two Pointers?</li></ol><p><strong>Special Variant: Three-way partitioning </strong>(you can figure this out on your own once you understand the pattern :)</p><p><strong>Three Pointers (Dutch National Flag Partitioning)</strong></p><p>Checkout my github for Two Pointer and It’s Patterns— <a href="https://github.com/Kaditya67/DSA/tree/learn/pattern/01-array/01-two-pointer">Two Pointer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=935772400b30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refresh your BFS and DFS]]></title>
            <link>https://medium.com/@kaditya67/refresh-your-bfs-and-dfs-5d06a33cff09?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d06a33cff09</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 12:31:01 GMT</pubDate>
            <atom:updated>2026-07-02T12:31:01.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXVPyviZEihIeAxZ6ylcKg.png" /></figure><p>Given an undirected connected graph with V vertices numbered from 0 to V-1, the task is to implement both Depth First Search (DFS) and Breadth First Search (BFS) traversals starting from the 0th vertex.</p><p>The graph is represented using an array/vector of edges, where each element is a pair [u, v] indicating an undirected edge between vertex u and vertex v.</p><p>Input: V = 5, edges = [ [0, 1], [0, 2], [0, 3], [2, 4] ]</p><pre>class Solution {<br>public:<br>    // Build Adjacency List<br>    void buildAdjancyList(vector&lt;vector&lt;int&gt;&gt;&amp; adj,<br>                          const vector&lt;vector&lt;int&gt;&gt;&amp; edges) {<br>        for (auto &amp;edge : edges) {<br>            int u = edge[0];<br>            int v = edge[1];<br><br>            adj[u].push_back(v);<br>            adj[v].push_back(u);   // Remove this line for directed graph<br>        }<br>    }<br><br>    // DFS Helper<br>    void dfs(int node,<br>             vector&lt;vector&lt;int&gt;&gt;&amp; adj,<br>             vector&lt;bool&gt;&amp; vis,<br>             vector&lt;int&gt;&amp; ans) {<br><br>        vis[node] = true;<br>        ans.push_back(node);<br><br>        for (int next : adj[node]) {<br>            if (!vis[next]) {<br>                dfs(next, adj, vis, ans);<br>            }<br>        }<br>    }<br><br>    // DFS Traversal<br>    vector&lt;int&gt; dfsOfGraph(int V, vector&lt;vector&lt;int&gt;&gt; edges) {<br><br>        vector&lt;vector&lt;int&gt;&gt; adj(V);<br>        buildAdjancyList(adj, edges);<br><br>        vector&lt;bool&gt; vis(V, false);<br>        vector&lt;int&gt; ans;<br><br>        dfs(0, adj, vis, ans);<br><br>        return ans;<br>    }<br><br>    // BFS Helper<br>    vector&lt;int&gt; bfs(vector&lt;vector&lt;int&gt;&gt;&amp; adj, int V) {<br><br>        vector&lt;bool&gt; vis(V, false);<br>        vector&lt;int&gt; ans;<br><br>        queue&lt;int&gt; q;<br><br>        q.push(0);<br>        vis[0] = true;<br><br>        while (!q.empty()) {<br><br>            int node = q.front();<br>            q.pop();<br><br>            ans.push_back(node);<br><br>            for (int next : adj[node]) {<br>                if (!vis[next]) {<br>                    vis[next] = true;<br>                    q.push(next);<br>                }<br>            }<br>        }<br><br>        return ans;<br>    }<br><br>    // BFS Traversal<br>    vector&lt;int&gt; bfsOfGraph(int V, vector&lt;vector&lt;int&gt;&gt; edges) {<br><br>        vector&lt;vector&lt;int&gt;&gt; adj(V);<br>        buildAdjancyList(adj, edges);<br><br>        return bfs(adj, V);<br>    }<br>};</pre><h3>1. buildAdjancyList()</h3><pre>void buildAdjancyList(...)</pre><ul><li>Converts the edge list into an adjacency list.</li><li>For every edge (u, v):</li><li>Add v to u&#39;s list.</li><li>Add u to v&#39;s list (because the graph is undirected).</li></ul><p>Example:</p><pre>Edges:<br>0-1<br>0-2<br>2-4</pre><pre>Adjacency List:<br>0 -&gt; 1 2<br>1 -&gt; 0<br>2 -&gt; 0 4<br>4 -&gt; 2</pre><h3>2. dfs()</h3><pre>void dfs(...)</pre><ul><li>Recursive function.</li><li>Marks the current node as visited.</li><li>Adds it to the answer.</li><li>Recursively visits every unvisited neighbor.</li></ul><p>Flow:</p><pre>Visit node<br>↓<br>Mark visited<br>↓<br>Store in answer<br>↓<br>Visit all unvisited neighbours</pre><h3>3. dfsOfGraph()</h3><pre>vector&lt;int&gt; dfsOfGraph(...)</pre><ul><li>Creates the adjacency list.</li><li>Creates the visited array.</li><li>Starts DFS from node 0.</li><li>Returns the traversal.</li></ul><h3>4. bfs()</h3><pre>vector&lt;int&gt; bfs(...)</pre><ul><li>Uses a <strong>queue</strong>.</li><li>Starts from node 0.</li><li>Repeatedly:</li><li>Remove the front node.</li><li>Add it to the answer.</li><li>Push all unvisited neighbors into the queue.</li></ul><p>Flow:</p><pre>Queue<br>↓<br>Take front node<br>↓</pre><pre>Visit it<br>↓</pre><pre>Push neighbours<br>↓</pre><pre>Repeat</pre><h3>5. bfsOfGraph()</h3><pre>vector&lt;int&gt; bfsOfGraph(...)</pre><ul><li>Builds the adjacency list.</li><li>Calls bfs().</li><li>Returns the traversal.</li></ul><h3>Time Complexity</h3><p>Building graph:</p><pre>O(E)</pre><p>DFS:</p><pre>O(V + E)</pre><p>BFS:</p><pre>O(V + E)</pre><p>where:</p><ul><li>V = number of vertices (nodes)</li><li>E = number of edges</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d06a33cff09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Find the Safest Path in a Grid]]></title>
            <link>https://medium.com/@kaditya67/find-the-safest-path-in-a-grid-79d480c4ed35?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d480c4ed35</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Wed, 01 Jul 2026 12:36:00 GMT</pubDate>
            <atom:updated>2026-07-01T12:36:00.889Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>The Problem</strong>: Read it yourself from the LeetCode…</p><p>What one think’s when you know just components in DSA but not actual HIT Algorithm…</p><pre>class Solution {<br>public:<br>    void bfsStorage(vector&lt;vector&lt;int&gt;&gt;&amp; storage, int rows, int cols, int i, int j) {<br>        queue&lt;pair&lt;pair&lt;int,int&gt;, int&gt;&gt; q;<br>        q.push({{i, j}, 0});<br><br>        int dr[] = {-1, 1, 0, 0};<br>        int dc[] = {0, 0, -1, 1};<br><br>        while (!q.empty()) {<br>            auto [cell, dist] = q.front();<br>            q.pop();<br><br>            int r = cell.first;<br>            int c = cell.second;<br><br>            if (storage[r][c] &lt;= dist)<br>                continue;<br><br>            storage[r][c] = dist;<br><br>            for (int k = 0; k &lt; 4; k++) {<br>                int nr = r + dr[k];<br>                int nc = c + dc[k];<br><br>                if (nr &gt;= 0 &amp;&amp; nr &lt; rows &amp;&amp;<br>                    nc &gt;= 0 &amp;&amp; nc &lt; cols) {<br><br>                    q.push({{nr, nc}, dist + 1});<br>                }<br>            }<br>        }<br>    }<br><br>    bool canReach(vector&lt;vector&lt;int&gt;&gt;&amp; storage, int mid) {<br>        int n = storage.size();<br>        int m = storage[0].size();<br><br>        if (storage[0][0] &lt; mid || storage[n-1][m-1] &lt; mid)<br>            return false;<br><br>        queue&lt;pair&lt;int,int&gt;&gt; q;<br>        vector&lt;vector&lt;bool&gt;&gt; vis(n, vector&lt;bool&gt;(m, false));<br><br>        q.push({0, 0});<br>        vis[0][0] = true;<br><br>        int dr[] = {-1, 1, 0, 0};<br>        int dc[] = {0, 0, -1, 1};<br><br>        while (!q.empty()) {<br>            auto [r, c] = q.front();<br>            q.pop();<br><br>            if (r == n-1 &amp;&amp; c == m-1)<br>                return true;<br><br>            for (int k = 0; k &lt; 4; k++) {<br>                int nr = r + dr[k];<br>                int nc = c + dc[k];<br><br>                if (nr &gt;= 0 &amp;&amp; nr &lt; n &amp;&amp;<br>                    nc &gt;= 0 &amp;&amp; nc &lt; m &amp;&amp;<br>                    !vis[nr][nc] &amp;&amp;<br>                    storage[nr][nc] &gt;= mid) {<br><br>                    vis[nr][nc] = true;<br>                    q.push({nr, nc});<br>                }<br>            }<br>        }<br><br>        return false;<br>    }<br><br>    int maximumSafenessFactor(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {<br>        int rows = grid.size();<br>        int cols = grid[0].size();<br><br>        vector&lt;vector&lt;int&gt;&gt; storage(rows, vector&lt;int&gt;(cols, INT_MAX));<br><br>        // Step 1: build distance to nearest 1<br>        for (int i = 0; i &lt; rows; ++i) {<br>            for (int j = 0; j &lt; cols; ++j) {<br>                if (grid[i][j] == 1) {<br>                    bfsStorage(storage, rows, cols, i, j);<br>                }<br>            }<br>        }<br><br>        // Step 2: binary search answer<br>        int low = 0, high = rows + cols, ans = 0;<br><br>        while (low &lt;= high) {<br>            int mid = (low + high) / 2;<br><br>            if (canReach(storage, mid)) {<br>                ans = mid;<br>                low = mid + 1;<br>            } else {<br>                high = mid - 1;<br>            }<br>        }<br><br>        return ans;<br>    }<br>};</pre><p>One would ask, why so much code, I will say, the approach took this many lines to meet the need…</p><p>What I GOT…!</p><figure><img alt="Failed at Last Testcase…" src="https://cdn-images-1.medium.com/max/731/1*jazy-TT018yHCp4E-verNA.png" /></figure><p>Finding problem…GOT the bottleneck…Solving….</p><p>The approach real name comes to:</p><ol><li><strong>Multi-Source BFS</strong></li><li><strong>Modified Dijkstra’s Algorithm (Maximum Bottleneck Path / Widest Path Problem)</strong></li></ol><h3>1. Multi-Source BFS</h3><p>This computes the distance from every cell to the <strong>nearest thief</strong>.</p><p>Instead of running BFS from every thief separately, all thieves are treated as starting points.</p><p><strong>Keywords to remember:</strong></p><ul><li>Multi-Source BFS</li><li>Distance Transform (on an unweighted grid)</li></ul><h3>2. Modified Dijkstra</h3><p>This part is <strong>not</strong> the normal shortest-path Dijkstra.</p><p>Normally, Dijkstra minimizes:</p><pre>distance = distance + edgeWeight</pre><p>Here, we’re maximizing:</p><pre>pathSafeness = min(currentPathSafeness, nextCellSafeness)</pre><p>The priority queue always expands the path with the <strong>highest current safeness</strong>.</p><p>This algorithm is commonly known as:</p><ul><li><strong>Maximum Bottleneck Path</strong></li><li><strong>Widest Path Problem</strong></li><li><strong>Max-Min Path</strong></li></ul><pre>class Solution {<br>public:<br>    int maximumSafenessFactor(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {<br>        int n = grid.size();<br><br>        vector&lt;vector&lt;int&gt;&gt; dist(n, vector&lt;int&gt;(n, -1));<br>        queue&lt;pair&lt;int,int&gt;&gt; q;<br><br>        // Multi-source BFS: Start from all thieves<br>        for (int i = 0; i &lt; n; i++) {<br>            for (int j = 0; j &lt; n; j++) {<br>                if (grid[i][j] == 1) {<br>                    dist[i][j] = 0;<br>                    q.push({i, j});<br>                }<br>            }<br>        }<br><br>        int dr[] = {-1, 1, 0, 0};<br>        int dc[] = {0, 0, -1, 1};<br><br>        while (!q.empty()) {<br>            auto [r, c] = q.front();<br>            q.pop();<br><br>            for (int k = 0; k &lt; 4; k++) {<br>                int nr = r + dr[k];<br>                int nc = c + dc[k];<br><br>                if (nr &gt;= 0 &amp;&amp; nr &lt; n &amp;&amp;<br>                    nc &gt;= 0 &amp;&amp; nc &lt; n &amp;&amp;<br>                    dist[nr][nc] == -1) {<br><br>                    dist[nr][nc] = dist[r][c] + 1;<br>                    q.push({nr, nc});<br>                }<br>            }<br>        }<br><br>        // Max Heap: {current path safeness, {row, col}}<br>        priority_queue&lt;pair&lt;int, pair&lt;int,int&gt;&gt;&gt; pq;<br><br>        vector&lt;vector&lt;int&gt;&gt; best(n, vector&lt;int&gt;(n, -1));<br><br>        pq.push({dist[0][0], {0, 0}});<br>        best[0][0] = dist[0][0];<br><br>        while (!pq.empty()) {<br>            auto [safe, cell] = pq.top();<br>            pq.pop();<br><br>            int r = cell.first;<br>            int c = cell.second;<br><br>            if (r == n - 1 &amp;&amp; c == n - 1)<br>                return safe;<br><br>            if (safe &lt; best[r][c])<br>                continue;<br><br>            for (int k = 0; k &lt; 4; k++) {<br>                int nr = r + dr[k];<br>                int nc = c + dc[k];<br><br>                if (nr &gt;= 0 &amp;&amp; nr &lt; n &amp;&amp;<br>                    nc &gt;= 0 &amp;&amp; nc &lt; n) {<br><br>                    int newSafe = min(safe, dist[nr][nc]);<br><br>                    if (newSafe &gt; best[nr][nc]) {<br>                        best[nr][nc] = newSafe;<br>                        pq.push({newSafe, {nr, nc}});<br>                    }<br>                }<br>            }<br>        }<br><br>        return 0;<br>    }<br>};</pre><p>This was finally done….</p><p>Grid<br> │<br> ▼<br>Multi-Source BFS<br> │<br> ▼<br>Distance to nearest thief<br> │<br> ▼<br>Modified Dijkstra (Maximum Bottleneck / Widest Path)<br> │<br> ▼<br>Answer</p><p>Try and let me know what you understand…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d480c4ed35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Linux — 100 Most Useful Commands — Part 10: Power Moves, Shortcuts & Real-World Workflows]]></title>
            <link>https://medium.com/@kaditya67/linux-100-most-useful-commands-part-10-power-moves-shortcuts-real-world-workflows-20b8cd436440?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/20b8cd436440</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Tue, 14 Apr 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-04-14T05:31:01.466Z</atom:updated>
            <content:encoded><![CDATA[<p>You now know the commands.</p><p>This final part is about:</p><ul><li><strong>working faster</strong></li><li><strong>combining commands</strong></li><li><strong>thinking like a power user</strong></li></ul><p>This is what separates someone who <em>knows commands</em> from someone who can actually <strong>use Linux efficiently</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-Efr4m2rkvrOXN5ERAdpA.png" /></figure><h3>1. alias - Create your own commands</h3><pre>alias ll=&quot;ls -la&quot;</pre><h3>Why this matters</h3><p>You remove repetitive typing.</p><h3>Real usage</h3><pre>alias gs=&quot;git status&quot;<br>alias run=&quot;npm start&quot;</pre><p>Now your workflow becomes faster.</p><h3>Make permanent</h3><p>Add to:</p><pre>~/.bashrc</pre><p>Then:</p><pre>source ~/.bashrc</pre><h3>2. history + reverse search (🔥)</h3><p>You already saw history, but this is next level.</p><h3>Press:</h3><pre>Ctrl + R</pre><p>Start typing → it finds previous commands instantly.</p><h3>Why this matters</h3><p>You almost never need to retype long commands again.</p><h3>3. &amp;&amp; - Chain commands safely</h3><pre>mkdir project &amp;&amp; cd project</pre><h3>What it does</h3><p>Runs next command <strong>only if previous succeeds</strong></p><h3>Why useful</h3><p>Prevents broken workflows.</p><h3>4. ; - Run commands regardless</h3><pre>command1 ; command2</pre><p>Runs both even if first fails.</p><h3>When to use</h3><ul><li>Logging</li><li>Non-critical steps</li></ul><h3>5. | (pipe) - Connect commands (🔥🔥)</h3><pre>cat file.txt | grep error</pre><h3>What it does</h3><p>Output of one command → input of another.</p><h3>Why this is powerful</h3><p>This is the <strong>core philosophy of Linux</strong></p><h3>Real example</h3><pre>grep &quot;ERROR&quot; log.txt | sort | uniq | wc -l</pre><h3>6. &gt; and &gt;&gt; - Redirect output</h3><pre>echo &quot;Hello&quot; &gt; file.txt</pre><h3>Difference</h3><ul><li>&gt; → overwrite</li><li>&gt;&gt; → append</li></ul><h3>Real usage</h3><pre>logs &gt; output.txt<br>logs &gt;&gt; output.txt</pre><h3>7. 2&gt; - Redirect errors</h3><pre>command 2&gt; error.log</pre><h3>Why useful</h3><p>Separate errors from output.</p><h3>Combine both</h3><pre>command &gt; output.log 2&gt;&amp;1</pre><h3>8. watch - Monitor continuously</h3><pre>watch -n 2 df -h</pre><p>Runs command every 2 seconds.</p><h3>Real usage</h3><ul><li>Monitor disk</li><li>Track logs</li><li>Observe changes</li></ul><h3>9. xargs (revisited) - Handle large outputs</h3><pre>find . -name &quot;*.log&quot; | xargs rm</pre><h3>Why important</h3><p>Efficient handling of multiple files.</p><h3>10. time - Measure execution time</h3><pre>time python script.py</pre><h3>What it shows</h3><ul><li>real time</li><li>user CPU time</li><li>system CPU time</li></ul><h3>Why useful</h3><ul><li>Performance testing</li><li>Optimization</li></ul><h3>🧩 Real-world workflows</h3><h3>1. Clean logs</h3><pre>find . -name &quot;*.log&quot; | xargs rm</pre><h3>2. Debug server</h3><pre>top &amp;&amp; df -h &amp;&amp; free -h</pre><h3>3. Analyze logs</h3><pre>grep &quot;ERROR&quot; app.log | sort | uniq | wc -l</pre><h3>4. Setup project quickly</h3><pre>mkdir app &amp;&amp; cd app &amp;&amp; touch main.py</pre><h3>⚠️ Common mistakes</h3><ul><li>Overusing sudo</li><li>Using ; instead of &amp;&amp;</li><li>Overwriting files with &gt; accidentally</li><li>Not using pipes effectively</li></ul><h3>Final Summary (All Parts)</h3><h3>🧱 Basics</h3><ul><li>navigation (cd, ls, pwd)</li><li>system awareness (whoami, date)</li></ul><h3>📂 File Management</h3><ul><li>create/delete (touch, rm, mkdir)</li><li>move/copy (mv, cp)</li></ul><h3>🔍 Data Processing</h3><ul><li>search (grep, find)</li><li>transform (awk, sed, cut)</li></ul><h3>🔐 Permissions</h3><ul><li>chmod, chown, sudo</li></ul><h3>⚙️ System &amp; Processes</h3><ul><li>ps, top, kill, nohup</li></ul><h3>💾 Resources</h3><ul><li>df, du, free, lscpu</li></ul><h3>🌐 Networking</h3><ul><li>ping, curl, netstat, traceroute</li></ul><h3>📦 DevOps Tools</h3><ul><li>tar, scp, rsync, crontab, systemctl</li></ul><h3>🚀 Power Usage</h3><ul><li>pipes, redirection, alias, chaining</li></ul><p>Now the next step is not more commands<br> it’s <strong>building real workflows and scripts using these</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20b8cd436440" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Linux — 100 Most Useful Commands — Part 9: Environment, Packages & Services (How Systems…]]></title>
            <link>https://medium.com/@kaditya67/linux-100-most-useful-commands-part-9-environment-packages-services-how-systems-94076342c1e6?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/94076342c1e6</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Mon, 13 Apr 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-04-13T05:31:01.450Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 Linux — 100 Most Useful Commands — Part 9: Environment, Packages &amp; Services (How Systems Actually Run)</h3><p>So far you’ve:</p><ul><li>navigated files</li><li>debugged processes</li><li>handled networking</li></ul><p>Now we move into <strong>how systems are configured and managed internally</strong>.</p><p>This is where backend + DevOps work really happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-Efr4m2rkvrOXN5ERAdpA.png" /></figure><h3>1. printenv - View environment variables</h3><pre>printenv</pre><h3>What it shows</h3><p>All environment variables.</p><h3>Useful check</h3><pre>printenv PATH</pre><h3>Why important</h3><ul><li>Debug why commands don’t work</li><li>Check runtime configuration</li></ul><h3>2. echo $VAR - Quick variable access</h3><pre>echo $HOME<br>echo $PATH</pre><h3>Why use this</h3><p>Faster than printenv for single variable.</p><h3>3. export - Set environment variables</h3><pre>export JAVA_HOME=/usr/lib/jvm/java-17</pre><h3>What it does</h3><p>Sets variable for current session.</p><h3>Example</h3><pre>export PATH=$JAVA_HOME/bin:$PATH</pre><h3>Why important</h3><ul><li>Configure tools (Java, Python, Node)</li><li>Used in scripts</li></ul><h3>4. source - Reload configuration</h3><pre>source ~/.bashrc</pre><h3>Why needed</h3><p>After updating env variables, apply changes without restarting terminal.</p><h3>5. env - Run command with custom env</h3><pre>env VAR=value command</pre><h3>Example</h3><pre>env DEBUG=true node app.js</pre><h3>Why useful</h3><p>Temporary environment override.</p><h3>6. apt - Package manager (Ubuntu/Debian)</h3><pre>sudo apt install nginx</pre><h3>Common commands</h3><pre>sudo apt update<br>sudo apt upgrade<br>sudo apt remove nginx</pre><h3>Why important</h3><ul><li>Install software</li><li>Update system</li><li>Manage dependencies</li></ul><h3>7. dpkg - Low-level package tool</h3><pre>dpkg -i package.deb</pre><h3>Why useful</h3><p>Install local .deb files.</p><h3>8. systemctl - Manage services (🔥 MUST KNOW)</h3><pre>sudo systemctl start nginx<br>sudo systemctl stop nginx</pre><h3>Check status</h3><pre>systemctl status nginx</pre><h3>Enable on boot</h3><pre>sudo systemctl enable nginx</pre><h3>Why important</h3><p>Controls:</p><ul><li>web servers</li><li>databases</li><li>background services</li></ul><h3>9. service - Older service manager</h3><pre>sudo service nginx start</pre><h3>Note</h3><p>systemctl is modern replacement.</p><h3>10. crontab - Schedule tasks (🔥 VERY IMPORTANT)</h3><pre>crontab -e</pre><h3>Example</h3><pre>0 2 * * * backup.sh</pre><p>Runs daily at 2 AM.</p><h3>Format</h3><pre>min hour day month weekday</pre><h3>Why important</h3><ul><li>Automation</li><li>Backups</li><li>Scheduled jobs</li></ul><h3>🧩 Real-world workflow</h3><p>Set environment + run server:</p><pre>export NODE_ENV=production<br>source ~/.bashrc<br>node app.js</pre><p>Install and run service:</p><pre>sudo apt install nginx<br>sudo systemctl start nginx</pre><p>Schedule backup:</p><pre>crontab -e</pre><h3>⚠️ Common mistakes</h3><ul><li>Forgetting to source after changes</li><li>Editing PATH incorrectly</li><li>Using sudo unnecessarily</li><li>Not enabling services on boot</li></ul><h3>Summary (Part 9)</h3><ul><li>printenv → view variables</li><li>echo $VAR → quick access</li><li>export → set variables</li><li>source → reload config</li><li>env → temporary variables</li><li>apt / dpkg → package management</li><li>systemctl → service control</li><li>crontab → scheduling</li></ul><p>Next part will be the <strong>final wrap-up (Part 10)</strong> — advanced utilities, tips, and how to combine everything into real-world workflows.</p><p>Stay tuned…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94076342c1e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Linux — 100 Most Useful Commands — Part 8: Archives, Compression & File Transfer]]></title>
            <link>https://medium.com/@kaditya67/linux-100-most-useful-commands-part-8-archives-compression-file-transfer-ab9864d85915?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab9864d85915</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Sun, 12 Apr 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-04-12T05:31:01.487Z</atom:updated>
            <content:encoded><![CDATA[<p>Now we move into something every developer uses but rarely understands properly:</p><p><strong>How data is packaged, compressed, and moved between systems</strong></p><p>This is critical for:</p><ul><li>Deployments</li><li>Backups</li><li>Sharing large files</li><li>CI/CD pipelines</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-Efr4m2rkvrOXN5ERAdpA.png" /></figure><h3>1. tar - Archive files (🔥 VERY IMPORTANT)</h3><pre>tar -czf archive.tar.gz folder/</pre><h3>What it does</h3><ul><li>Combines multiple files into one</li><li>Compresses them</li></ul><h3>Flags explained</h3><ul><li>c → create</li><li>z → gzip compression</li><li>f → file name</li></ul><h3>Extract</h3><pre>tar -xzf archive.tar.gz</pre><h3>Why this matters</h3><p>Most production backups and deployments use .tar.gz</p><h3>2. gzip / gunzip - Compress single file</h3><pre>gzip file.txt<br>gunzip file.txt.gz</pre><h3>Key difference from tar</h3><ul><li>gzip → compresses ONE file</li><li>tar → combines + compresses multiple</li></ul><h3>Keep original file</h3><pre>gzip -k file.txt</pre><h3>3. zip / unzip - Cross-platform compression</h3><pre>zip files.zip file1 file2<br>unzip files.zip</pre><h3>Why important</h3><ul><li>Works well with Windows/Mac</li><li>Used for sharing</li></ul><h3>4. scp - Copy files to remote server (🔥)</h3><pre>scp file.txt user@server:/path/</pre><h3>What it does</h3><p>Secure file transfer over SSH.</p><h3>Copy folder</h3><pre>scp -r folder/ user@server:/path/</pre><h3>Real usage</h3><p>Deploy app:</p><pre>scp app.zip ubuntu@server:/var/www/</pre><h3>5. rsync - Smart file transfer (🔥🔥)</h3><pre>rsync -av folder/ user@server:/path/</pre><h3>Why better than scp</h3><ul><li>Only transfers changed files</li><li>Faster for large data</li><li>Can resume</li></ul><h3>Real usage</h3><pre>rsync -av --progress project/ server:/backup/</pre><h3>6. wget - Download files (revisited)</h3><pre>wget https://example.com/file.tar.gz</pre><h3>Why still important here</h3><p>Often used before extracting archives.</p><h3>7. curl -O - Download via curl</h3><pre>curl -O https://example.com/file.tar.gz</pre><h3>Difference from wget</h3><ul><li>More flexible for APIs</li><li>Also used for downloads</li></ul><h3>8. du -sh - Check archive size</h3><pre>du -sh archive.tar.gz</pre><h3>Why useful</h3><p>Verify file size before transfer.</p><h3>9. split - Split large files</h3><pre>split -l 1000 bigfile.txt</pre><h3>What it does</h3><p>Breaks file into smaller chunks.</p><h3>Real usage</h3><ul><li>Sending large files</li><li>Processing big datasets</li></ul><h3>10. cat (revisited) - Merge split files</h3><pre>cat xaa xab &gt; merged.txt</pre><h3>Why important</h3><p>Reverse operation of split.</p><h3>🧩 Real-world workflow</h3><p>Backup and transfer project:</p><pre>tar -czf project.tar.gz project/<br>scp project.tar.gz server:/backup/</pre><p>Efficient sync:</p><pre>rsync -av project/ server:/backup/</pre><h3>⚠️ Common mistakes</h3><ul><li>Confusing tar vs gzip</li><li>Using scp for large repeated transfers (use rsync)</li><li>Forgetting -r for folders</li><li>Not checking file size before transfer</li></ul><h3>Summary (Part 8)</h3><ul><li>tar → archive + compress</li><li>gzip → compress single file</li><li>zip → cross-platform compression</li><li>scp → simple file transfer</li><li>rsync → efficient transfer</li><li>wget / curl → download</li><li>split → break large files</li><li>cat → merge files</li></ul><p>Next part will cover <strong>environment variables, packages, and services</strong> — how systems are configured and run in the background!</p><p>Stay tuned…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab9864d85915" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Linux — 100 Most Useful Commands — Part 7: Networking & Connectivity (Debug Like a Backend…]]></title>
            <link>https://medium.com/@kaditya67/linux-100-most-useful-commands-part-7-networking-connectivity-debug-like-a-backend-5ac32eceeec7?source=rss-f8ef5b2a3304------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ac32eceeec7</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Aditya Ojha]]></dc:creator>
            <pubDate>Sat, 11 Apr 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-04-11T05:31:01.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 Linux — 100 Most Useful Commands — Part 7: Networking &amp; Connectivity (Debug Like a Backend Engineer)</h3><p>Now we step into <strong>networking</strong> — one of the most important skills in real-world systems.</p><p>Most production issues are not code issues.<br> They are:</p><ul><li>Server not reachable</li><li>Port not open</li><li>Network latency</li><li>DNS issues</li></ul><p>This part teaches you how to <strong>debug all of that from terminal</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-Efr4m2rkvrOXN5ERAdpA.png" /></figure><h3>1. ping - Check if a server is reachable</h3><pre>ping google.com</pre><h3>What it does</h3><p>Sends ICMP packets to check connectivity.</p><h3>What to look at</h3><ul><li>time= → latency</li><li>packet loss</li></ul><h3>Real usage</h3><pre>ping api.server.com</pre><p>If it fails → either:</p><ul><li>server is down</li><li>network issue</li><li>ICMP blocked</li></ul><h3>2. curl - Talk to APIs directly (🔥 MUST KNOW)</h3><pre>curl https://api.github.com</pre><h3>What it does</h3><p>Fetches data from a URL.</p><h3>Real backend usage</h3><pre>curl -X POST https://api.com/login \<br>     -H &quot;Content-Type: application/json&quot; \<br>     -d &#39;{&quot;user&quot;:&quot;admin&quot;}&#39;</pre><h3>Why important</h3><ul><li>Test APIs</li><li>Debug backend without frontend</li><li>Used in scripts</li></ul><h3>3. wget - Download files</h3><pre>wget https://example.com/file.zip</pre><h3>Difference from curl</h3><ul><li>wget → download-focused</li><li>curl → request/response focused</li></ul><h3>4. ifconfig / ip addr - Network interfaces</h3><pre>ifconfig<br># or modern<br>ip addr</pre><h3>Shows</h3><ul><li>IP address</li><li>network interfaces</li></ul><h3>Real usage</h3><p>Find your machine IP:</p><pre>ip addr</pre><h3>5. netstat - Check open ports (🔥)</h3><pre>netstat -tuln</pre><h3>What it shows</h3><ul><li>open ports</li><li>listening services</li></ul><h3>Example</h3><pre>netstat -tuln | grep 3000</pre><p>Check if backend is running on port 3000.</p><h3>Modern replacement</h3><pre>ss -tuln</pre><h3>6. lsof - Which process is using a port</h3><pre>lsof -i :3000</pre><h3>Why important</h3><p>If port is busy → find the process using it.</p><h3>Real fix</h3><pre>kill -9 PID</pre><h3>7. telnet Test port connectivity</h3><pre>telnet google.com 80</pre><h3>What it does</h3><p>Checks if a port is reachable.</p><h3>Real usage</h3><ul><li>Check if DB port is open</li><li>Debug firewall issues</li></ul><h3>8. traceroute - Track network path</h3><pre>traceroute google.com</pre><h3>What it shows</h3><p>All hops between you and destination.</p><h3>Why useful</h3><ul><li>Debug slow network</li><li>Identify where delay occurs</li></ul><h3>9. hostname -I - Get local IP quickly</h3><pre>hostname -I</pre><h3>Why useful</h3><p>Faster than ifconfig for quick IP check.</p><h3>10. nslookup - DNS resolution</h3><pre>nslookup google.com</pre><h3>What it does</h3><p>Resolves domain → IP</p><h3>Real usage</h3><p>Check DNS issues:</p><pre>nslookup api.server.com</pre><h3>🧩 Real-world debugging flow</h3><p>Website not working:</p><pre>ping server.com<br>nslookup server.com<br>curl server.com<br>netstat -tuln<br>lsof -i :3000</pre><h3>⚠️ Common mistakes</h3><ul><li>Thinking server is down without checking ping</li><li>Not checking if port is open</li><li>Ignoring DNS issues</li><li>Using only browser instead of curl</li></ul><h3>Summary (Part 7)</h3><ul><li>ping → connectivity</li><li>curl → API testing</li><li>wget → download files</li><li>ip addr / ifconfig → network info</li><li>netstat / ss → open ports</li><li>lsof → process using port</li><li>telnet → port check</li><li>traceroute → network path</li><li>hostname -I → local IP</li><li>nslookup → DNS</li></ul><p>Next part will cover <strong>archives, compression, and file transfer</strong> — essential for deployments and backups!</p><p>Stay tuned…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac32eceeec7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>