<?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 Shini Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Shini Agarwal on Medium]]></description>
        <link>https://medium.com/@shiniagarwal25?source=rss-bf6fbee6ddc5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XQuM0kawW2ZxvvdU</url>
            <title>Stories by Shini Agarwal on Medium</title>
            <link>https://medium.com/@shiniagarwal25?source=rss-bf6fbee6ddc5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:39:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shiniagarwal25/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 Changed How I See Arrays]]></title>
            <link>https://medium.com/@shiniagarwal25/kadanes-algorithm-changed-how-i-see-arrays-df09264c2f21?source=rss-bf6fbee6ddc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/df09264c2f21</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Shini Agarwal]]></dc:creator>
            <pubDate>Tue, 13 May 2025 13:31:16 GMT</pubDate>
            <atom:updated>2025-05-13T13:31:16.942Z</atom:updated>
            <content:encoded><![CDATA[<h3>Algorithms Are Tough</h3><p>I’ve always found algorithms super hard. I would try to solve coding problems and end up stuck, staring at my screen and feeling dumb. But I’m done with that. I want to make algorithms easy for people like me who get lost in the jargon. So I am starting this blog series: <strong><em>DSA in Plain English</em></strong>. It’s me explaining data structures and algorithms in a way that actually makes sense.</p><p>First up is Kadane’s Algorithm. It’s about finding the best chunk of numbers in an array. It totally changed how I think about arrays. Let’s get into it.</p><h3>What’s Kadane’s Algorithm?</h3><p>Kadane’s Algorithm solves this popular problem: you have an array of numbers (some positive, some negative), and you need to find the subarray of numbers next to each other that adds up to the biggest total. For example, take the array [-2, 1, -3, 4, -1, 2, 1, -5, 4]. The subarray [4, -1, 2, 1] adds up to 6, and that’s the biggest sum you can get. <a href="https://leetcode.com/problems/maximum-subarray/description/">https://leetcode.com/problems/maximum-subarray/description/</a></p><p>At first I thought to just check every possible subarray, right? Nope. That takes forever if the array is big (O(n²)). Kadane’s does it one quick pass through the array. It’s like finding the fastest route home without checking every road.</p><h3>How It Works</h3><p>Here’s the deal: you go through the array one number at a time. You keep track of two things:</p><ul><li>The best sum you’ve found so far (maxi).</li><li>The sum of the subarray you’re working on right now (sum).</li></ul><p>If adding a number makes sum negative, you start fresh with just the next number. A negative sum is like carrying dead weight as it won’t help you get a bigger total later. If sum is bigger than maxi, you update maxi.</p><h4>Step-by-Step Walkthrough</h4><p><strong>Array</strong>: [-2, 1, -3, 4, -1, 2, 1, -5, 4]</p><p><strong>Initialization</strong>:<br>maxi = INT_MIN<br>sum = 0</p><p><strong>i = 1 (nums[1] = -2)</strong>:</p><ul><li>sum = 0 + (-2) , which is less than 0<br>Hence sum = 0</li><li>maxi = INT_MIN</li></ul><p><strong>i = 2 (nums[2] = 1)</strong>:</p><ul><li>sum = 0 + 1</li><li>maxi = 1</li></ul><p><strong>i = 3 (nums[3] = -3)</strong>:</p><ul><li>sum = 1+ (-3) , which is less than 0<br>Hence sum = 0</li><li>maxi = 1</li></ul><p><strong>i = 4 (nums[4] = 4)</strong>:</p><ul><li>sum = 0 + 4</li><li>maxi = 4</li></ul><p><strong>i = 5 (nums[5] = -1)</strong>:</p><ul><li>sum = 4 –1</li><li>maxi = 4</li></ul><p><strong>i = 6 (nums[6] = 2)</strong>:</p><ul><li>sum = 3+ 2</li><li>maxi = 5</li></ul><p><strong>i = 7 (nums[7] = 1)</strong>:</p><ul><li>sum = 5+1</li><li>maxi = 6</li></ul><p><strong>i = 8 (nums[8] = -5)</strong>:</p><ul><li>sum = 5–5</li><li>maxi = 6</li></ul><p><strong>Return</strong>: maxi = 6</p><p>The maximum subarray sum is 6, which corresponds to the subarray [4, -1, 2, 1] (sum = 4 + (-1) + 2 + 1 = 6).</p><h3>The Code</h3><p>Here’s how it looks in C++. It’s short but powerful:</p><pre>#include &lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>long long maxSubarraySum(int arr[], int n) {<br>    long long maxi = LONG_MIN;<br>    long long sum = 0;<br><br>    for (int i = 0; i &lt; n; i++) {<br><br>        sum += arr[i];<br><br>        if (sum &gt; maxi) {<br>            maxi = sum;<br>        }<br><br>        if (sum &lt; 0) {<br>            sum = 0;<br>        }<br>    }<br>    return maxi;<br>}<br><br>int main()<br>{<br>    int arr[] = { -2, 1, -3, 4, -1, 2, 1, -5, 4};<br>    int n = sizeof(arr) / sizeof(arr[0]);<br>    long long maxSum = maxSubarraySum(arr, n);<br>    cout &lt;&lt; &quot;The maximum subarray sum is: &quot; &lt;&lt; maxSum &lt;&lt; endl;<br>    return 0;<br>}</pre><h3>Why This Blew My Mind</h3><p>Kadane’s showed me you don’t need to overcomplicate things. It’s not about checking every option but about making smart choices as you go. Do I keep this sum or start over? That kind of thinking has helped me with other coding problems too. It’s like learning to pack light for a trip.</p><h3>What’s Coming Up</h3><p>This is just the start. I’m gonna write more about stuff like binary search, linked lists, and dynamic programming. All in plain English, no fancy talk. If algorithms stress you out, hang with me. We’ll figure it out together.</p><p>What do you think of Kadane’s? Got any algorithm struggles? Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df09264c2f21" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>