<?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 Premaranjan Dilujan on Medium]]></title>
        <description><![CDATA[Stories by Premaranjan Dilujan on Medium]]></description>
        <link>https://medium.com/@preamaranjan-dilujan?source=rss-9a47db8772a2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Hj_-VplYgkm2nGYcV5Ho6A.jpeg</url>
            <title>Stories by Premaranjan Dilujan on Medium</title>
            <link>https://medium.com/@preamaranjan-dilujan?source=rss-9a47db8772a2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 16:25:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@preamaranjan-dilujan/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[Permutations Problem — Everything I Was Confused About (And How I Finally Got It)]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/permutations-problem-everything-i-was-confused-about-and-how-i-finally-got-it-71e6c987251e?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e6c987251e</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Fri, 15 May 2026 02:10:57 GMT</pubDate>
            <atom:updated>2026-05-15T02:10:57.606Z</atom:updated>
            <content:encoded><![CDATA[<p>I did not learn permutations from a tutorial. I learned it by being confused — five times — and solving each confusion one by one. This article is the result of that process. If you have ever stared at a backtracking solution and thought “I understand each line but not the whole thing,” this is for you.</p><h3>What Even Is a Permutation?</h3><p>A permutation is every possible ordering of a set of elements.</p><p>For [1, 2, 3], all permutations are:</p><pre>[1,2,3]  [1,3,2]  [2,1,3]  [2,3,1]  [3,1,2]  [3,2,1]</pre><p>Total = 3 × 2 × 1 = <strong>6</strong></p><p>Why 3 × 2 × 1? Because you have 3 choices for the first spot, 2 for the second, and 1 for the last. That is it.</p><h3>The Approach I Found Clearest — Swap-Based Backtracking</h3><p>There are three common approaches to this problem. I found the swap-based backtracking (Approach 2 in most resources) the most intuitive once I understood what was actually happening. Here is the code:</p><pre>def permute(nums):<br>    result = []<br><br>    def backtrack(start):<br>        if start == len(nums):<br>            result.append(nums[:])<br>            return<br><br>        for i in range(start, len(nums)):<br>            nums[start], nums[i] = nums[i], nums[start]   # swap in<br>            backtrack(start + 1)                           # next position<br>            nums[start], nums[i] = nums[i], nums[start]   # swap back<br><br>    backtrack(0)<br>    return result</pre><p>Seven lines. But every single line confused me at some point. Let me walk through each confusion.</p><h3>Confusion 1 — What Does “Backtrack” Actually Mean?</h3><p>I kept reading “backtracking” as if it were a special algorithm. It is not.</p><p>Think of a maze. You walk down a path, hit a dead end, and walk back to the last junction to try a different path.</p><p><strong>That walking back = backtracking.</strong></p><p>In code, it means exactly this:</p><blockquote><em>I tried something. I am done with it. Undo it. Try the next option.</em></blockquote><p>That is the whole concept. Make a choice, explore it fully, undo it, try the next choice. Nothing more.</p><h3>Confusion 2 — What Does “Fix” Mean in the Recursion Tree?</h3><p>Every explanation I read said things like “fix 1 at position 0.” I had no idea what “fix” meant.</p><p>Here is the analogy that made it click for me.</p><p><strong>Imagine 3 people and 3 chairs in a row.</strong></p><pre>Chair 1    Chair 2    Chair 3<br>  [ ]        [ ]        [ ]</pre><pre>People:  1,  2,  3</pre><p>“Fix 1 at position 0” simply means — <strong>person 1 has sat down in chair 1.</strong> They are seated. Done. Stop thinking about chair 1. Move to chair 2.</p><p>That is the entire meaning of the word “fix.” Once someone is seated, that position is decided and you move on.</p><p>So when you see this tree:</p><pre>[ ][ ][ ]</pre><pre>        Who sits in Chair 1?<br>       /          |          \<br>    1 sits      2 sits      3 sits</pre><p>It just means: three people are available for chair 1, so you try each one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*egIKuHNkBGz9Yn0PfEDHsw.png" /></figure><h3>Confusion 3 — Why Is the For Loop Written? Where Does It Come From?</h3><p>This was my biggest confusion. I could not see where the for loop came from mentally.</p><p><strong>Here is how it comes from your brain.</strong></p><p>You are standing at chair 1. You look at all available people. You ask yourself:</p><blockquote><em>“Who can sit here?”</em></blockquote><p>Your eyes scan every available person one by one:</p><pre>Can 1 sit here? Yes → try it<br>Can 2 sit here? Yes → try it<br>Can 3 sit here? Yes → try it</pre><p><strong>That scanning = the for loop.</strong></p><p>python</p><pre>for i in range(start, len(nums)):</pre><p>Now you move to chair 2. One person is already seated. You only scan the remaining people. That is why the range starts at start — not at 0. Everything before start is already seated and you never touch it.</p><pre>Chair 1 → scan positions 0,1,2   → range(0, 3)<br>Chair 2 → scan positions 1,2     → range(1, 3)<br>Chair 3 → scan position 2        → range(2, 3)<br>Chair 4 → nobody left            → base case, record it</pre><p>The for loop exists because <strong>at every chair, multiple people can try it.</strong> You try each one, explore what happens, undo it, and try the next. That trying-each-option is exactly what the for loop does.</p><h3>Confusion 4 — Swap and Backtrack. What Is Each One Doing?</h3><p>Once I understood chairs and people, the two operations became obvious.</p><p>python</p><pre>nums[start], nums[i] = nums[i], nums[start]   # person sits in the chair<br>backtrack(start + 1)                           # move to the next chair<br>nums[start], nums[i] = nums[i], nums[start]   # pe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*h-w7GLTnrqLI7MzffKhgXw.png" /></figure><p><strong>Swap decides who sits. Backtrack moves to the next chair. Swap back undoes so the loop can try the next person.</strong></p><p>Three lines, three jobs.</p><p>The swap uses the array itself as both the seating arrangement and the list of available people. After swap(0, 1) on [1, 2, 3]</p><pre>Before:  [1, 2, 3]<br>After:   [2, 1, 3]<br>          ^<br>          2 is now in chair 1 — seated<br>             ^ ^<br>             still standing, available for chair 2</pre><p>Everything after start is still available. Everything before start is already seated.</p><h3>Confusion 5 — The Swap I Almost Missed at the Last Position</h3><p>When I traced through the code carefully, I noticed something every explanation was hiding.</p><p>Even at the <strong>last chair</strong> — when only one person is left — a swap still happens before recording.</p><p>Here is what actually happens at position 2:</p><pre>backtrack(start=2)<br><br>  for i in range(2, 3):   ← only one person to scan<br><br>    swap(2,2) → [1, 2, 3]        ← THIS SWAP STILL HAPPENS<br>    backtrack(start=3)<br>    → start == len(nums) → record [1, 2, 3]<br>    swap back(2,2) → [1, 2, 3]   ← AND THIS SWAP BACK TOO</pre><p>swap(2, 2) swaps index 2 with itself — the array does not change visually. But the swap executes in code every single time.</p><p>Think of it like this: even when only one person is left standing, the code still asks them — “do you want to sit in chair 3?” They say yes, sit down, the arrangement is recorded, then they stand back up.</p><p><strong>Every leaf node in the recursion tree has a swap before recording.</strong> No exceptions.</p><h3>The Full Trace — Nothing Hidden</h3><p>Here is the complete trace for [1, 2, 3] with every swap shown:</p><pre>backtrack(start=0)<br><br>├── i=0: swap(0,0) → [1,2,3]   &quot;1 in chair 1&quot;<br>│   backtrack(start=1)<br>│   ├── i=1: swap(1,1) → [1,2,3]   &quot;2 in chair 2&quot;<br>│   │   backtrack(start=2)<br>│   │   └── i=2: swap(2,2) → [1,2,3]   &quot;3 in chair 3&quot;<br>│   │       backtrack(start=3) → ✅ record [1,2,3]<br>│   │       swap back(2,2) → [1,2,3]<br>│   │   swap back(1,1) → [1,2,3]<br>│   │<br>│   └── i=2: swap(1,2) → [1,3,2]   &quot;3 in chair 2&quot;<br>│       backtrack(start=2)<br>│       └── i=2: swap(2,2) → [1,3,2]   &quot;2 in chair 3&quot;<br>│           backtrack(start=3) → ✅ record [1,3,2]<br>│           swap back(2,2) → [1,3,2]<br>│       swap back(1,2) → [1,2,3]<br>│   swap back(0,0) → [1,2,3]<br>│<br>├── i=1: swap(0,1) → [2,1,3]   &quot;2 in chair 1&quot;<br>│   backtrack(start=1)<br>│   ├── i=1: swap(1,1) → [2,1,3]   &quot;1 in chair 2&quot;<br>│   │   backtrack(start=2)<br>│   │   └── i=2: swap(2,2) → [2,1,3]   &quot;3 in chair 3&quot;<br>│   │       backtrack(start=3) → ✅ record [2,1,3]<br>│   │       swap back(2,2) → [2,1,3]<br>│   │   swap back(1,1) → [2,1,3]<br>│   │<br>│   └── i=2: swap(1,2) → [2,3,1]   &quot;3 in chair 2&quot;<br>│       backtrack(start=2)<br>│       └── i=2: swap(2,2) → [2,3,1]   &quot;1 in chair 3&quot;<br>│           backtrack(start=3) → ✅ record [2,3,1]<br>│           swap back(2,2) → [2,3,1]<br>│       swap back(1,2) → [2,1,3]<br>│   swap back(0,1) → [1,2,3]<br>│<br>└── i=2: swap(0,2) → [3,2,1]   &quot;3 in chair 1&quot;<br>    backtrack(start=1)<br>    ├── i=1: swap(1,1) → [3,2,1]   &quot;2 in chair 2&quot;<br>    │   backtrack(start=2)<br>    │   └── i=2: swap(2,2) → [3,2,1]   &quot;1 in chair 3&quot;<br>    │       backtrack(start=3) → ✅ record [3,2,1]<br>    │       swap back(2,2) → [3,2,1]<br>    │   swap back(1,1) → [3,2,1]<br>    │<br>    └── i=2: swap(1,2) → [3,1,2]   &quot;1 in chair 2&quot;<br>        backtrack(start=2)<br>        └── i=2: swap(2,2) → [3,1,2]   &quot;2 in chair 3&quot;<br>            backtrack(start=3) → ✅ record [3,1,2]<br>            swap back(2,2) → [3,1,2]<br>        swap back(1,2) → [3,2,1]<br>    swap back(0,2) → [1,2,3]</pre><p>Six results. Six leaf nodes. Every single one goes through a swap before recording.</p><h3>The Mental Model in One Place</h3><p>If you remember nothing else, remember this:</p><blockquote><strong><em>n people, n chairs. Fill each chair one by one.</em></strong></blockquote><ul><li><strong>For loop</strong> — scan every person still standing for the current chair</li><li><strong>Swap in</strong> — that person sits down</li><li><strong>backtrack(start + 1)</strong> — move to the next chair and repeat</li><li><strong>Swap back</strong> — person stands up so the next person can try</li><li><strong>Base case</strong> — all chairs are filled, record the arrangement</li><li><strong>The swap always happens</strong> — even at the last chair with one person left</li></ul><h3>Complexity</h3><p>ValueTimeO(n × n!)SpaceO(n) stack + O(n × n!) for output</p><p>You cannot do better than O(n!) — that is how many permutations exist. The extra ×n is for copying each arrangement of length n.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e6c987251e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[# Prefix Sum — From Road Trip to Efficient Algorithms]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/prefix-sum-from-road-trip-to-efficient-algorithms-3a63deb59056?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a63deb59056</guid>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Mon, 11 May 2026 12:19:50 GMT</pubDate>
            <atom:updated>2026-05-11T12:35:09.725Z</atom:updated>
            <content:encoded><![CDATA[<h3>Prefix Sum — From Road Trip to Efficient Algorithms</h3><h3>Introduction</h3><p>In this post, I will walk you through:</p><ul><li>What Prefix Sum is</li><li>How to build it step by step</li><li>Left Sum and Right Sum</li><li>Why we subtract in Prefix Sum</li><li>Real code implementation</li></ul><h3>The Road Trip Analogy 🚗</h3><p>Imagine you are on a road trip with three cities:</p><pre>START --7km-- A --2km-- B --5km-- C</pre><p>The distances between cities are:</p><pre>array = [7, 2, 5]</pre><p>Now if someone asks — <strong>“How far is the total journey to each city from START?”</strong></p><p>You would naturally calculate:</p><pre>START to A = 7km<br>START to B = 7 + 2 = 9km<br>START to C = 7 + 2 + 5 = 14km</pre><p><strong>That is exactly what Prefix Sum does!</strong></p><h3>What is Prefix Sum?</h3><blockquote><em>👉 At every index, store the </em><strong><em>running total</em></strong><em> up to that point!</em></blockquote><pre>array  = [7,  2,  5]<br>prefix = [7,  9, 14]<br>index =   0   1   2</pre><p>Think of it like a car <strong>odometer</strong> — it always shows the total distance travelled so far!</p><h3>How to Build Prefix Sum — Step by Step</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMy-fIhFwnmLWnsEkrfvFg.png" /></figure><pre>array = [7, 2, 5]</pre><h3>Index 0</h3><pre>running total = 7<br>prefix[0] = 7</pre><h3>Index 1</h3><pre>running total = 7 + 2 = 9<br>prefix[1] = 9</pre><h3>Index 2</h3><pre>running total = 7 + 2 + 5 = 14<br>prefix[2] = 14</pre><h3>Result</h3><pre>prefix = [7, 9, 14]  ✅</pre><h3>Left Sum and Right Sum</h3><p>These are two powerful concepts built on top of Prefix Sum.</p><h3>Left Sum</h3><blockquote><em>👉 Sum of everything </em><strong><em>BEFORE</em></strong><em> the current index</em></blockquote><pre>START --7km-- A --2km-- B --5km-- C</pre><p>Position Left Sum Why A (index 0) 0 nothing before A! B (index 1) 7 only A is before B C (index 2) 9 A and B are before C</p><h3>Right Sum</h3><blockquote><em>👉 Sum of everything </em><strong><em>AFTER</em></strong><em> the current index</em></blockquote><pre>START --7km-- A --2km-- B --5km-- C</pre><p>Position Right Sum Why A (index 0) 7 B and C are after A (2+5=7) B (index 1) 5 only C is after B C (index 2) 0 nothing after C!</p><h3>Why Do We Subtract in Prefix Sum?</h3><p>This is the most confusing part for beginners — let me explain clearly!</p><h3>Question — Right Sum of B using Prefix Sum?</h3><p>We want to find the distance <strong>after B</strong> which is just 5km (to C).</p><pre>prefix[C] = 14  →  total distance to C<br>prefix[B] = 9   →  total distance to B</pre><p>Both values include the <strong>same START to B journey!</strong></p><pre>prefix[C] = START→A→B→C = 7 + 2 + 5 = 14<br>prefix[B] = START→A→B   = 7 + 2     = 9</pre><p>When we subtract:</p><pre>14 - 9<br>= (7 + 2 + 5) - (7 + 2)<br>= 5  ✅</pre><blockquote><em>👉 The common part (START to B) </em><strong><em>cancels out!</em></strong><em> Only the distance AFTER B remains!</em></blockquote><h3>Complete Example</h3><pre>array  = [7,  2,  5]<br>prefix = [7,  9, 14]<br>index =   0   1   2</pre><h3>For index 1 (Town B):</h3><pre>left sum  = prefix[0]              = 7<br>element   = arr[1]                 = 2<br>right sum = prefix[2] - prefix[1]  = 14 - 9 = 5</pre><pre>verify →<br>left + element + right<br>= 7 + 2 + 5<br>= 14  ✅</pre><h3>The Code</h3><pre>using System;</pre><pre>class Program<br>{<br>    static void PrefixSum(int[] arr)<br>    {<br>        int n = arr.Length;<br>        int[] prefix = new int[n];</pre><pre>        // build prefix sum<br>        prefix[0] = arr[0];<br>        for (int i = 1; i &lt; n; i++)<br>        {<br>            prefix[i] = prefix[i - 1] + arr[i];<br>        }</pre><pre>        // calculate left and right sum for each index<br>        for (int i = 0; i &lt; n; i++)<br>        {<br>            int leftSum  = i &gt; 0 ? prefix[i - 1] : 0;<br>            int rightSum = prefix[n - 1] - prefix[i];</pre><pre>            Console.WriteLine($&quot;Index {i} → Left: {leftSum}, Element: {arr[i]}, Right: {rightSum}&quot;);<br>        }<br>    }</pre><pre>    static void Main()<br>    {<br>        int[] arr = { 7, 2, 5 };<br>        PrefixSum(arr);<br>    }<br>}</pre><h3>Output</h3><pre>Index 0 → Left: 0,  Element: 7, Right: 7<br>Index 1 → Left: 7,  Element: 2, Right: 5<br>Index 2 → Left: 9,  Element: 5, Right: 0</pre><h3>Time Complexity</h3><pre>Build prefix sum → O(n)<br>Query any range  → O(1)</pre><pre>Total → O(n)  ✅</pre><p>Without prefix sum, every range query takes O(n). With prefix sum, every range query takes O(1)!</p><h3>Key Takeaways</h3><ol><li>Prefix Sum stores the <strong>running total</strong> at every index</li><li>Left Sum = everything <strong>before</strong> current index</li><li>Right Sum = everything <strong>after</strong> current index</li><li>We subtract because the <strong>common journey cancels out!</strong></li><li>Prefix Sum turns O(n) queries into O(1)!</li></ol><h3>Conclusion</h3><p>The Prefix Sum technique is a beautiful example of how <strong>pre-computing</strong> can save enormous time. Just like knowing the total distance to each city on a road trip helps you instantly calculate any sub-journey, Prefix Sum helps you instantly calculate any subarray sum!</p><p>Next time you see a problem asking for <strong>range sums or subarray queries</strong>, think Prefix Sum!</p><blockquote><strong><em>Pre-compute once, query in O(1) forever!</em></strong><em> 🚀</em></blockquote><p><em>Happy Coding! 🚀</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a63deb59056" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximum Subarray Problem — From Brute Force to Kadane’s Algorithm]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/maximum-subarray-problem-from-brute-force-to-kadanes-algorithm-d84f42921361?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d84f42921361</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Sun, 10 May 2026 11:30:45 GMT</pubDate>
            <atom:updated>2026-05-10T11:30:45.749Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A step-by-step guide to understanding</blockquote><h3>Introduction</h3><p>In this post, I will walk you through:</p><ul><li>What the problem is</li><li>The brute force approach</li><li>Kadane’s Algorithm — the optimal solution</li><li>The connection between both approaches</li></ul><h3>What is the Problem?</h3><p>Given an array of integers, find the <strong>subarray with the maximum sum</strong> and return that sum.</p><pre>array  = [2, -1, 3, -2, 5]<br>answer = 7<br>because [2, -1, 3, -2, 5] = 7  ✅</pre><h3>What is a Subarray?</h3><p>A subarray is a <strong>continuous</strong> part of the array.</p><pre>array = [2, -1, 3, -2, 5]</pre><pre>valid subarrays →<br>[2]<br>[2, -1]<br>[2, -1, 3]<br>[-1, 3]<br>[3, -2, 5]</pre><pre>NOT valid →<br>[2, 3]    ← skips -1!<br>[2, -2]   ← skips elements!</pre><h3>Approach 1 — Brute Force O(n²)</h3><p>The most natural approach is to check <strong>every possible subarray</strong> and track the maximum sum.</p><h3>Key Idea</h3><p>Instead of using 3 loops, we can use 2 loops by keeping a <strong>running sum</strong> as we go.</p><pre>static int MaxSubArray(int[] arr)<br>{<br>    int n   = arr.Length;<br>    int max = int.MinValue;</pre><pre>    for (int i = 0; i &lt; n; i++)<br>    {<br>        int sum = 0;<br>        for (int j = i; j &lt; n; j++)<br>        {<br>            sum += arr[j];       // keep adding<br>            if (sum &gt; max)<br>                max = sum;       // update max<br>        }<br>    }<br>    return max;<br>}</pre><h3>Trace</h3><pre>array = [2, -1, 3, -2, 5]</pre><pre>i=0 → [2]=2, [2,-1]=1, [2,-1,3]=4, [2,-1,3,-2]=2, [2,-1,3,-2,5]=7<br>i=1 → [-1]=-1, [-1,3]=2, [-1,3,-2]=0, [-1,3,-2,5]=5<br>i=2 → [3]=3, [3,-2]=1, [3,-2,5]=6<br>i=3 → [-2]=-2, [-2,5]=3<br>i=4 → [5]=5</pre><pre>maximum = 7  ✅</pre><h3>Complexity</h3><pre>Time  → O(n²)<br>Space → O(1)</pre><h3>Approach 2 — Kadane’s Algorithm O(n)</h3><p>Joseph Born Kadane invented this algorithm in 1984 to solve this exact problem in <strong>O(n) time.</strong></p><h3>Key Observation</h3><p>At every position there are only <strong>2 choices:</strong></p><pre>choice 1 → continue adding to current sum<br>choice 2 → start fresh from current element</pre><p>Always pick the <strong>bigger one!</strong></p><h3>Why Only 2 Choices?</h3><p>Look at subarrays ending at index 2:</p><pre>[2, -1, 3]  → previous subarray [2,-1] + current 3<br>[-1, 3]     → previous subarray [-1]   + current 3<br>[3]         → just current 3 alone (start fresh)</pre><p>Every subarray ending here is either a <strong>previous subarray + current element</strong> or <strong>just the current element alone.</strong> No other option exists!</p><h3>Why Pick the Bigger One?</h3><p>Think of it like collecting money 💰</p><pre>Positive number = gain money 💰<br>Negative number = lose money 💸</pre><p>If your current sum is <strong>negative</strong>, carrying it forward will drag future elements down. So it is better to <strong>start fresh!</strong></p><pre>carrying -2 forward →  -2 + 5 = 3   😰<br>starting fresh      →       5 = 5   😊</pre><h3>The Code</h3><pre>static int MaxSubArray(int[] arr)<br>{<br>    int currentSum = arr[0];<br>    int max        = arr[0];</pre><pre>    for (int i = 1; i &lt; arr.Length; i++)<br>    {<br>        // continue or start fresh?<br>        currentSum = Math.Max(arr[i], currentSum + arr[i]);</pre><pre>        // update max<br>        max = Math.Max(max, currentSum);<br>    }<br>    return max;<br>}</pre><h3>Trace</h3><pre>array = [2, -1, 3, -2, 5]</pre><pre>i=0 → currentSum=2   max=2<br>i=1 → MAX(-1, 2-1)  = MAX(-1, 1) = 1    max=2<br>i=2 → MAX(3,  1+3)  = MAX(3,  4) = 4    max=4<br>i=3 → MAX(-2, 4-2)  = MAX(-2, 2) = 2    max=4<br>i=4 → MAX(5,  2+5)  = MAX(5,  7) = 7    max=7  ✅</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/0*XLy-y0e7WZfFuDTT.png" /></figure><h3>Complexity</h3><pre>Time  → O(n)<br>Space → O(1)</pre><h3>Connection Between Both Approaches</h3><p>Normal Way Kadane’s Way Check ALL subarrays ending here Only check BEST of previous + current Many comparisons Only 2 comparisons! O(n²) O(n)</p><p>The key insight is that the <strong>best previous subarray always gives the best result</strong> when extended. So we only need to track the best — not all of them!</p><h3>Final Comparison</h3><p>Approach Time Space Brute Force O(n²) O(1) Kadane’s Algorithm O(n) O(1)</p><h3>Key Takeaways</h3><ol><li>A subarray must be <strong>continuous</strong> — no skipping elements!</li><li>At every position ask — <strong>continue or start fresh?</strong></li><li><strong>Never carry a negative sum forward</strong> — it only makes things worse!</li><li>Kadane’s Algorithm reduces O(n²) to O(n) by tracking only the <strong>best previous subarray!</strong></li></ol><h3>Conclusion</h3><p>The Maximum Subarray Problem is a brilliant example of how a simple observation can turn a slow O(n²) solution into a blazing fast O(n) algorithm. Kadane’s key insight was that we do not need to check all subarrays — just the best one at each step!</p><p>Next time you see this problem in an interview, remember:</p><blockquote><strong><em>Continue or start fresh? Always pick the bigger one!</em></strong></blockquote><p><em>Happy Coding! 🚀</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d84f42921361" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Using Two-Pass Sorting: Master the Dutch National Flag Algorithm The Concept]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/stop-using-two-pass-sorting-master-the-dutch-national-flag-algorithm-the-concept-2dfb566fb3b2?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dfb566fb3b2</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Sun, 03 May 2026 09:59:30 GMT</pubDate>
            <atom:updated>2026-05-03T09:59:30.399Z</atom:updated>
            <content:encoded><![CDATA[<p>The DNF algorithm is a “three-way partition” strategy. Imagine you are a gatekeeper with three zones:</p><ol><li><strong>The Zero Zone (Red):</strong> Everything to the left of the low pointer.</li><li><strong>The One Zone (White):</strong> The space between low and mid.</li><li><strong>The Two Zone (Blue):</strong> Everything to the right of the high pointer.</li></ol><h3>Why does the ‘mid’ pointer stay put for 2s?</h3><p>This is the most common question readers will have. The logic is based on <strong>certainty vs. uncertainty</strong>:</p><ul><li><strong>Swapping with </strong><strong>low (for 0s):</strong> The mid pointer has already walked past the low area. We know that whatever is at low is a <strong>1</strong>. When we swap a <strong>0</strong> into low and a <strong>1</strong> into mid, we are 100% sure the new value at mid is a <strong>1</strong>. Therefore, we can safely move the mid scout forward.</li><li><strong>Swapping with </strong><strong>high (for 2s):</strong> The high pointer is at the far end of the array in the &quot;unexplored territory.&quot; When we swap a <strong>2</strong> to the back, the value we pull into the mid spot is <strong>unknown</strong>. It could be a <strong>0</strong> that needs to go to the front or a <strong>1</strong> that belongs right here. If we moved mid forward, we might &quot;skip&quot; a <strong>0</strong>, leaving it trapped in the middle of the array.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JbKni-aaUkS4hAsjugMGzA.png" /></figure><h3>C# Implementation</h3><p>This code is optimized for readability, which is perfect for a technical tutorial.</p><pre>public void SortColors(int[] nums) <br>{<br>    int low = 0;<br>    int mid = 0;<br>    int high = nums.Length - 1;<br><br>    while (mid &lt;= high) <br>    {<br>        if (nums[mid] == 0) <br>        {<br>            // We know what&#39;s at low (likely a 1), so mid can move forward.<br>            Swap(nums, low, mid);<br>            low++;<br>            mid++;<br>        } <br>        else if (nums[mid] == 1) <br>        {<br>            // 1s are already in the middle, just move the scout.<br>            mid++;<br>        } <br>        else // nums[mid] == 2<br>        {<br>            // We don&#39;t know what&#39;s at high! Stay at mid to check the new value.<br>            Swap(nums, mid, high);<br>            high--;<br>        }<br>    }<br>}<br><br>private void Swap(int[] nums, int i, int j) <br>{<br>    int temp = nums[i];<br>    nums[i] = nums[j];<br>    nums[j] = temp;<br>}</pre><h3>Key Performance Takeaways for your readers:</h3><ul><li><strong>Time Complexity:</strong> $O(n)$ — We iterate through the array exactly once.</li><li><strong>Space Complexity:</strong> $O(1)$ — We sort everything “in-place” without creating a new list or array.</li><li><strong>The “One-Pass” Advantage:</strong> Unlike a standard Counting Sort which requires two passes (one to count and one to overwrite), DNF achieves the result in a single traversal.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dfb566fb3b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to statistics — part-2]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/introduction-to-statistics-part-2-41fcba8f2170?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/41fcba8f2170</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 06:15:00 GMT</pubDate>
            <atom:updated>2023-04-20T06:15:00.827Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to statistics — part-2</h3><h3>Log-normal distribution</h3><p>plot the log of data points(x1, x2, x3,…). for example,</p><p>x1 =&gt; log(x1), x2 =&gt; log(x2), x3 =&gt; log(x3) then graph will become the skew plot (either positive skew or negative skew).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*K6OIOkLqUcbiBAWIwktCBQ.png" /></figure><h3>Central limit theorem</h3><p>If any particular variable (x) (the population data) might belongs to the Gaussian distribution. over the particular variable, randomly select samples having a size is &gt;= 30.</p><p>{x1, x2, x3 , x4, x5 are samples; s1 — s30 data points; x̄1 is sample mean of x1}</p><p>x1 -&gt; s1 — s30 -&gt; x̄1</p><p>x2 -&gt; s1 — s60 -&gt; x̄3</p><p>x3-&gt; s61 — s90 -&gt; x̄3</p><p>x4 -&gt; s91 — s120 -&gt; x̄4</p><p>x5 -&gt; s121 — s150 -&gt; x̄5</p><p>then,</p><ul><li>All the samples’ means will be equal to the population mean.</li><li>All the samples will possess/show the Gaussian distribution.</li></ul><h3>Chebyshev inequality</h3><p>If any particular sample belongs to the Gaussian distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XXmFcatWBkagH3YeYdpig.png" /></figure><p>If any particular sample doesn&#39;t belong to the Gaussian distribution, then the distribution of the sample.</p><p>The formula for finding out the percentage distribution of a particular region</p><p>k = standard deviations (<strong>σ will replace with k)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Y99pRtvOeBnpTTc1TF2pIg.png" /></figure><p>For example, k = 2 to find out the percentage distribution of the region.</p><p><strong>μ-2k &lt; — &gt; μ+2k ≥ 1-(1/2²)</strong></p><p><strong>≥ 75%</strong></p><p>75% of data in the particular region.</p><h3>P-Value</h3><h3>Hypothesis</h3><p>1, What is the hypothesis?</p><ul><li>whenever some assumption about population parameters there that we called a hypothesis</li></ul><p>For example, you have made medicine for diseases. the medicine was tested on U.S people. what has been found is that 20 mg of the dose is sufficient for a person&#39;s cure. this particular assumption has been made for the complete population based on the sample study.</p><h4>Type of hypothesis</h4><p><strong>1, Null hypothesis</strong></p><ul><li>The assumption that has been made for the population that is assumed to be true until it is declared false.</li></ul><p>For example, 20 mg of dose for a person is sufficient. the particular hypothesis is true till now and is being followed as a null hypothesis.</p><p><strong>2, Alternative hypothesis</strong></p><ul><li>It is a claim about the population that is contradictory to null hypothesis.</li></ul><h4>Hypothesis testing</h4><p>Let’s say we are given two distributions. now we do some statistics on those diestibution and try to make hypothesis, whether the two distributions belongs to the same population or are they significantly different. the hypothesis which says the two belongs to the same population is termed as Null Hypothesis, while the other one is termed as Alternate Hypothesis.</p><p>to check the correctiness of the hypothesis, we use tests called:</p><ul><li>t-test</li><li>z-test</li></ul><p><strong>t-test or z-test</strong></p><p>Both t-test and z-test are similar and even share the similar formula. the difference is that when the <strong>sample size</strong>/disribution size (number of points in the dataset) is greater than 30, the test is called z-test and for the lesser number of data points, the test is called the t-test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*_ZmggnDc1ufRvGh1TDGQqg.png" /></figure><p>Steps to check the hypothesis</p><ul><li>Check the assumption (make sure the distribution behaves similar to normal distribution).</li><li>Check weather the testing is one-tail testing or two-tail testing.</li><li>Set the significance (p-value) level.</li></ul><p>For example the significance level is 0.5</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41fcba8f2170" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git and Bitbucket]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/git-and-bitbucket-bfa543c142a2?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa543c142a2</guid>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 06:14:14 GMT</pubDate>
            <atom:updated>2023-04-20T06:14:14.947Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>What are Git and Bitbucket?</li><li>Installing the Git repository tool in the local machine</li><li>Creating a project in bitbucket and adding users to the respective project in Bitbucket</li><li>Configuring user credentials in developer machine</li><li>Creating development projects and connecting with Bitbucket</li><li>Managing Git branches and keeping track of different versions</li><li>Add changes to the remote repository</li><li>What is .gitgnore?</li></ul><h4>1 — What are Git and Bitbucket?</h4><p>Git</p><ul><li>Git is a distributed repository management tool (version control tool).</li><li>It contains a set of commands in order to manage the project repository.</li></ul><p>Bitbucket</p><ul><li>Bitbucket provides a service to host the repository in the cloud/physical server that configures Bitbucket.</li></ul><blockquote>Git and Bitbucket work together in order to manage the repository</blockquote><h4>2 — Installing the Git repository tool</h4><p>Click <a href="https://git-scm.com/">download </a>and install — <a href="https://git-scm.com/">https://git-scm.com/</a></p><h4>3 — Creating a project in bitbucket and adding users to the respective project in Bitbucket</h4><ul><li><a href="https://id.atlassian.com/signup?application=bitbucket&amp;continue=https%3A%2F%2Fbitbucket.org%2Faccount%2Fsignin%2F%3Fnext%3D%252F">Sign up</a> or <a href="https://id.atlassian.com/login?application=bitbucket&amp;continue=https%3A%2F%2Fbitbucket.org%2Faccount%2Fsignin%2F%3Fnext%3D%252F%26redirectCount%3D1">Log in</a> to the bitbucket account.</li><li>Create a project and repository.</li><li>Adding users who will work in the repository with permissions.</li></ul><h4>4 — Configuring user credentials in the developer machine</h4><p>open the git bash and follow the commands,</p><p>note: Use the user name and email which were integrated with Bitbucket.</p><p><strong>git config — global user.name ‘user_name’<br>git config — global user.email ‘user@testmail.com’</strong></p><p>To see all the global parameters: git config — list</p><h4>5 — Working with the remote repository(clone repo)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhrO0XvghUm8ciZ713BG6A.png" /><figcaption>Create a folder and open the Git bash</figcaption></figure><p>after the Git bash opens the following steps in the bash,</p><p>i - clone the repository to that folder.</p><p><strong>git clone </strong><a href="https://Dilujan97@bitbucket.org/dilujan97/test_repo.git"><strong>https://user@bitbucket.org/user/test_repo.git</strong></a></p><p>If you facing any authentication issues, watch this <a href="https://youtu.be/BvHLCTGapu0">video</a>.</p><p>Managing Git branches and keeping track of different versions</p><h4>6 — Managing Git branches and keeping track of different versions</h4><p>Note: The default branch is the master.</p><blockquote>Optional steps are done by the project admin,</blockquote><p>i — Create a new branch</p><p>note: change the directory (cd test_repo) into the git repository that was cloned.</p><p><strong>git branch br_dev1</strong></p><ul><li>in the project, each developer has their own branch which is used to push changes in the project that was done by the specific developer.</li><li>When we create a new branch from a previous branch, it takes the copy of the previous branch. for example, in our case we create a new branch br_dev1 from the master branch, therefore br_dev1 branch takes the copy of the source code from the master branch.</li></ul><p>ii — Switch into the created branch</p><p><strong>git checkout br_dev1</strong></p><p>ii i— Initialized the created branch in the remote repository.</p><ul><li>Every branch has two copies of the branch.</li></ul><p>a— local copy/repository (master, dev1) — The version maintains in the local machine</p><p>b — remote copy/repository (remotes/origin/master) — The branch maintains in the remote server.</p><ul><li>It is important for which branch is updating work with the project.</li></ul><p><strong>git push -u origin br_dev1 — </strong>create br_dev1 in the remote repository and push everything in the local branch into the remote branch.</p><h4>7 — Add changes to the remote repository.</h4><blockquote>now I’m in the <strong>br_dev1 </strong>branch.</blockquote><p>i — Make changes in existing files from local the machine.</p><p>ii —<strong> git status</strong></p><ul><li>show all the changes.</li><li>in our case add, and modify files available in the local project file(local uncommitted changes) not in the <strong>br_dev1 </strong>branch.</li></ul><p>iii — <strong>git add .</strong></p><ul><li>adding those changes to staging area.</li></ul><p>iv —<strong> git commit -m “this is my first commit”</strong></p><ul><li>commit all the changes into the local repository of the particular branch(<strong>br_dev1 </strong>branch).</li></ul><p>v — <strong>git push</strong></p><ul><li>push all the changes in the local repository into the remote repository of the particular branch(<strong>br_dev1 </strong>branch).</li></ul><p>vi — merge the changes that are available in the remote repository of the particular branch(<strong>br_dev1 </strong>branch) into the master branch.</p><ul><li><strong>git checkout master — </strong>first, switch to the master branch.</li><li><strong>git merge origin/br_dev1 — </strong>merge local master branch from changes available in remote <strong>br_dev1 </strong>branch</li><li><strong>git push</strong> — push all the things available in the local master branch into the remote master branch</li></ul><p>8 — How next developer get the updated code form repository?</p><p>i —<strong> git clone </strong><a href="https://Dilujan97@bitbucket.org/dilujan97/test_repo.git"><strong>https://user@bitbucket.org/user/test_repo.git</strong></a></p><ul><li>clone the repository of the particular project into a particular local directory (one time enough).</li></ul><p>ii — navigate into the respective cloned project</p><p>iii — <strong>git branch br_dev2</strong></p><ul><li>create a new branch done by admin (one time enough)</li></ul><p>iv — <strong>git checkout br_dev2</strong></p><ul><li>switch into particular branch</li></ul><p>v — <strong>git push -u origin br_dev2</strong></p><ul><li>create br_dev2 in the remote repository and push everything in the local branch into the remote branch.</li></ul><p>vi — <strong>git pull origin master</strong></p><ul><li>Pull the update from the master branch</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa543c142a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/firebase-2a795d535418?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a795d535418</guid>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 06:12:53 GMT</pubDate>
            <atom:updated>2023-04-20T06:12:53.237Z</atom:updated>
            <content:encoded><![CDATA[<p>firebase is a backend as a service. it provides back-end services such as database, authentication, file storage, cloud functions, hosting, etc. we can directly use those services in our frontend applications or websites.</p><h4>Advantages</h4><ul><li>Developers don’t need to focus on backend infrastructure.</li><li>Most of features are completely free.</li><li>More optimized output code and a smaller file size.</li></ul><h4>Difference between firebase v8 and v9</h4><ul><li>Adopts to modular and <a href="https://firebase.google.com/docs/auth/web/password-auth">functional approach </a>— import the firebase functions from the libraries. v8 used object oriented approach(we want call functions using firebase objects)</li><li>Tree shaking — only importing the necessary functions which means unused functions remove from our final bundled JavaScript file to do that we need modular bundler like webpack or rollup.</li></ul><h4>Firebase database and auth service</h4><blockquote>To use the v9 we need to step up module bundler like webpack</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a795d535418" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to statistics]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/introduction-to-statistics-773b6ea474fe?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/773b6ea474fe</guid>
            <category><![CDATA[central-tendency]]></category>
            <category><![CDATA[correlation-coefficient]]></category>
            <category><![CDATA[standard-deviation]]></category>
            <category><![CDATA[variance]]></category>
            <category><![CDATA[normal-distribution]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 05:49:45 GMT</pubDate>
            <atom:updated>2023-02-09T05:49:45.348Z</atom:updated>
            <content:encoded><![CDATA[<h3>Probability</h3><p><strong>Chance</strong>/Likelihood <strong>of something to happen</strong>. assuming the future(this will happen).</p><h3>Statistics</h3><p>It is about analyzing (the distribution of data, data pattern, the outlier of data, statistical property, mean of data, standard deviation, and correlation of the features) data. <strong>analyzing the past data.</strong></p><p><strong><em>In data science what is important Probability or Statistics?</em></strong></p><ul><li>We are getting past data, analyzing the data, researching the data, and making the conclusion. then, we are going to probability.</li><li>Example: based on past data. based on past data. we can predict whether the patient has a disease or not.</li></ul><blockquote>We can use statistics to calculate the probability.</blockquote><h3>Probability</h3><p>i — Event/Experiment</p><p>A <strong>possible outcome of the scenario</strong> is possible or realistic. When tossing the coin, either get head or tail.</p><p>ii — Sample space</p><p>A set of all event values.</p><p>Example: when rolling the two dice together, the sort of combination is like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*W6zKLu5YI3lH5o7eNfWbLA.gif" /><figcaption>socratic.org</figcaption></figure><p>in total(sample space) 6 x 6 = 36 event values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*MTXD4wiqQ_eQ0oYVrKaOOA.jpeg" /><figcaption>math-only-math.com</figcaption></figure><p>Question: What would be the sample space when rolling the dice and tossing the coin together?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*PuadTOdm-rnJYaf27j9dLg.gif" /><figcaption>onlinemathlearning.com</figcaption></figure><p>Answer: 2 x 6= 12 {coin — head, tail; dice — 1,2,3,4,5,6}</p><p>iii — Probability of event (E)</p><p>P(E) = num of time event occurs n(E) / num.of sample space n(S.S)</p><p>Question: When rolling two dice together, What is the probability of an odd number in dice one and an even number in dice two?</p><p>Answer: 9/36 = 1/4</p><p><strong><em>The 1st event is dependent on the 2nd event dependent which is called the dependent event otherwise the event is independent.</em></strong></p><blockquote>Example: person A rolls a dice. he gets number 5. and then person B rolls a dice. his dice don’t have the number got by person A. Here, the second event depends on the first event. the first event probability is 1/6 and the second event probability is 1/5.</blockquote><h3>Statistics</h3><p>It is the discipline that concerns the collecting organizing, analyzing, and interpreting of the data (what they’re in data), distribution of data, the correlation between the data, and conclusion from the data.</p><p>Two types of statistics</p><p>1 — Descriptive statistics</p><p>It involves analyzing the data, summarizing the data, and organizing the data in form of a graph.</p><p>Example: Bar plot, Histogram, Pi-chart, PDF, Normal distribution, the measure of central tendency.</p><p>2 — Inferential statistics</p><p>Sample statistics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*FGHGubSYPLhwwco9-4i7Kg.png" /></figure><p>Example: The population is the state. is it possible for the news reporter to meet every people in the state and get their opinion? — No <br>They interview some person in every region in the state and then finally conclude.</p><blockquote>here, Some samples are made from the population. finally, a conclusion was made for the entire population based on the conclusion that was made from the sample.</blockquote><p>i — Population mean</p><p>If the population is very low, the conclusion will be made from the population level.</p><p>the sum of all the samples in the population / total number of samples</p><p>ii — Sample mean</p><p>If the population is very high, the conclusion will be made from the sample level.</p><p>the sum of all the people in the sample / total number of people in the sample</p><h3>Random variable</h3><h4>numerical variable</h4><p>a — discrete random variable</p><p>Example: Whole number, no of the bank account the person holds. (4 bank accounts not 4.1 accounts)</p><p>b — continuous random variable</p><p>Float number, whole number. within any range of value, we can have either float or whole number.</p><p>Example:</p><p>** The height of a person ranges from 3m to 7m. it can be 3, 3.8, 5, or 6.67m.</p><p>** The range of the marks 0 to 100</p><h4>categorical variable</h4><p>Data may be divided into groups. Example: Sex, Age</p><h3>Central tendency</h3><p>The measure of central tendency is a measure of the central value of the data.</p><p>1 — mean</p><ul><li>average of the data points.</li><li>Disadvantage: the mean value gets affected a lot by the presence of outliers.</li></ul><blockquote>Outliers: exceptional points of dataset either very large or very small value.</blockquote><p>2 — Median</p><ul><li>The middle value in the dataset is arranged in order either ascending or <br>descending.</li></ul><p>3 — Mode</p><ul><li>More frequent value of the dataset. generally use to find out the most frequent<br>categorical value of the dataset.</li></ul><h3>Variability</h3><p>variability for any data describes how spread out the data is.</p><p>1 — Range</p><ul><li>It is the difference between the maximum value and the minimum value in the dataset.</li><li>The outliers make the result worse because the max would be very<br>higher and the min would be very lower.</li></ul><p>For example, the range of the dataset is 2 to 10, but the outlier coming 50. then, the range of the dataset is 2 to 50. but, the actual is 2 to 10.</p><p>2 — Interquartile range(IQR)</p><p>It’s similar to a range, but the difference is, that we are not just concerned with the difference between the max and min values in the dataset, but we are also concerned with where the middle values are lying.</p><p><strong>IQR = Q3-Q1</strong></p><p>Q3: 3rd Quartile (75 Percentile)</p><p>Q1: 1st Quartile (25 Percentile)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*4WDw89cHeYleHVsUIxlRdQ.png" /><figcaption>Box plot</figcaption></figure><p>The boxplot is used to find out the interquartile range because it decides the data as outliers and quartiles.</p><h3>Variance</h3><p>Variance tries to calculate the data’s spread using the squared <strong>distance of the data points(xi) from the mean( X̅) of the data points.</strong></p><figure><img alt="https://www.onlinemathlearning.com/variance.html" src="https://cdn-images-1.medium.com/max/538/1*u30j_EKf_IiZapjtBPVw4Q.png" /></figure><h3>Standard deviation</h3><p>It is similar to variance, as it’s just the square root of the variance.</p><figure><img alt="https://www.thoughtco.com/calculate-a-sample-standard-deviation-3126345" src="https://cdn-images-1.medium.com/max/259/1*qbq0UDkcIiRv5l2JCsL-6g.png" /></figure><h3>Gaussian distribution / normal distribution</h3><p>Majority of the time the data be in this format.</p><p>Example: x is the random variable. it has some data stored. the data has mean and Standard deviation. the distribution of the data is something like this.</p><figure><img alt="kanbanize.com" src="https://cdn-images-1.medium.com/max/1024/1*0XXmFcatWBkagH3YeYdpig.png" /><figcaption>Normal (Gaussian) Distribution</figcaption></figure><ul><li>in the middle mean (μ) of the data.</li><li>Distribution pattern</li></ul><p>***** 1σ one standard deviation away from mean = μ + 1σ</p><ul><li>If any data points are thereafter 3σ, then that will be considered an outlier.</li><li>68% of the distribution is between 1σ and -1σ.</li></ul><p>The shape of the normal distribution depends on the standard deviation and the mean of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2jFMgSMCb2Q8gcC29JKgA.jpeg" /><figcaption>Normal distribution</figcaption></figure><h4>Skewness of data</h4><blockquote>Skewness means (graph shifter positive side or negative side)</blockquote><p>1 — Positive skew: The majority of values are on the negative side of the graph.</p><p>Example for distribution of the height of the persons. the mean of the distribution is 5 feet. so the majority of the persons are below 5 feet.</p><p>2 — Negative skew: The majority of the values are on the positive side of the graph.</p><figure><img alt="https://www.analyticsvidhya.com/blog/2020/07/what-is-skewness-statistics/" src="https://cdn-images-1.medium.com/max/1024/1*JVeW93KKKrND-IOF8a4QLw.jpeg" /></figure><h3>Standard normal distribution</h3><p>Using the Z-score to standardization of data means “converting normal distribution into the standard normal distribution.”{convert all values in same range} we can define that the particular data will have a <strong>mean of zero and a standard deviation of one</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GkbRgCcGtg2t_V5I-1Vvw.png" /><figcaption>scribbr.com</figcaption></figure><h3>Scaling of the data</h3><p>Standardization part of the scaling data as well as standardization used to convert normal distribution into standard normal distribution.</p><p>example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sdj2hIZN8yyQwXE9QFrltw.jpeg" /><figcaption>healthynex.com</figcaption></figure><p>above image humans know the height in feet and weight in kg, but the machine understands those parameters as the only numbers and weight values are greater than the height value, so the weight values are more important than height values. but actually, it is not true. both parameters are equally important. if not, the model becomes biased with the weight parameter. that’s why feature scaling will be done. so, all the sorts of numbers are in the same range.</p><p>Two types of feature scaling,</p><p>1 — Normalization: Convert every value range from 0 to 1.</p><p><strong><em>x</em> normalized = (<em>x</em> — <em>x</em> minimum) / (<em>x</em> maximum — <em>x</em> minimum)</strong></p><p>x = particular value; x min = min of the value; x max = max of the value.</p><p>2 — Standardization: Distribution means of zero and standard deviation of one.</p><figure><img alt="https://python.plainenglish.io/how-to-de-normalize-and-de-standardize-data-in-python-b4600cf9ee6?gi=af2bbade0772" src="https://cdn-images-1.medium.com/max/485/1*iYSFjgCGD8IhYBgciQnGow.png" /></figure><blockquote>In the machine learning model standardization is better and deep learning model normalization is better.</blockquote><h3>Correlation vs Causation</h3><p>in statistics, two variables are termed to be related, if the value of one changes if the value of another one increases or decreases.</p><p><strong>The difference between correlation and causation with the help of an example</strong></p><p>We go to buy a house. the two variables, the size of the house and the price of the house are correlated with each other. The bigger the size of the house, the larger the price. so we may say the two variables are correlated.</p><p>The causation indicates, that Event B only changes if the value of event A only changes. the previous example can be a Correlation but not a Causation. because not only the size of the house but also the house’s location also change the house’s price. the rural areas house is low price. the house near to town is a high price. house price is dependent on another factor house’s location other than the house’s size.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=773b6ea474fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Data Structures and Algorithms]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/introduction-to-data-structures-and-algorithms-998947c06ad9?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/998947c06ad9</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Sat, 13 Aug 2022 14:21:23 GMT</pubDate>
            <atom:updated>2022-08-13T14:22:05.163Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>There are 5000 students in the school. Their names are stored in the register without alphabetical order. your task is “find out the student’s name who starts with D ”.</blockquote><p>It is a difficult task without ordering their names in alphabetical order.</p><p><strong>What is a Data Structure?</strong></p><ul><li>Data — any value or set of values</li></ul><p>Ex: The set of students’ names</p><ul><li>Structure — arrangement of and relations between these data</li></ul><p>Ex: Arrange alphabtecilaly the name</p><p>Data may be organized in different ways (Ex: alphabetically, numerically, ascending, descending, etc.) and the logical or mathematical model of a particular organization of data is called a <strong>data structure</strong>.</p><p>In simpler terms, a data structure is a <strong>particular way of organizing data </strong>within a computer so that it can be used effectively.</p><p>Ex: organizing the students’ names alphabetically is efficient for us to access students’ names. extraction of data is easy when using the data structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*1nbULSraQPmoYlGd.png" /></figure><ul><li>Primitive data structure — built-in data structure which means it is defined by language.</li><li>Non-primitive data structure — it is derived from the primitive data structure.</li></ul><h4>Which data structure should you use?</h4><ul><li>The model must be rich enough in structure to mirror the actual relationship of the data in the real world.</li><li>It should be simple enough that one can effectively process the data whenever necessary.</li></ul><h4>What is an algorithm?</h4><p>An algorithm is known as any well-defined computational procedure that takes in input in the form of some value or set of values and produces an output in the form of some value or set of values.</p><p>for example, the steps to make a tea</p><pre>Begin</pre><pre>      Take the hot water</pre><pre>      Mix with tea powder</pre><pre>      Add milk</pre><pre>      Add the sugar</pre><pre>      Mix all things</pre><pre>      Take tea</pre><pre>Stop</pre><p><em>The above step to make something(tea) is an algorithm. here input parameters are hot water, tea powder, sugar, and milk. output tea.</em></p><p>Formerly defined, an algorithm is a <strong>sequence of computational steps</strong> that transform the <strong>input into the output</strong>.</p><h4>Correctness and characteristics of the algorithms</h4><ul><li>The algorithm will be correct. if and only that gives the correct output for every input.</li></ul><p>Ex: Correct algorithm works every input for the given computational problem, and the incorrect algorithm doesn’t work some input or gives an invalid answer.</p><h4>Characteristics of the algorithmic problem.</h4><ul><li>They have several solutions. finding the best among them.</li></ul><p>Ex: a sorting problem is solved by multiple algorithms such as selection sort, merge sort, queue sort, and insertion sort. the best algorithm is selected by analyzing the performance time, flexibility, complexity, etc.</p><ul><li>They have practical application</li></ul><p>Ex: finding the shortest path between two places.</p><blockquote>What is the <strong>import of algorithms</strong>? say your answer in the <strong>comments</strong>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=998947c06ad9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks]]></title>
            <link>https://medium.com/@preamaranjan-dilujan/react-hooks-4a59fc6af5d9?source=rss-9a47db8772a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a59fc6af5d9</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[usestate-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-state]]></category>
            <dc:creator><![CDATA[Premaranjan Dilujan]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 13:42:23 GMT</pubDate>
            <atom:updated>2021-12-28T13:42:23.928Z</atom:updated>
            <content:encoded><![CDATA[<p>React hooks are JavaScript functions.</p><h4>It has some rules.</h4><ul><li>Only call Hooks at the top level. Don’t call the hooks inside loops, conditions or nested functions.</li><li>Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions.</li></ul><h4>How shall we use State Hook {useState}?</h4><pre>import { useState } from &#39;react&#39;;<br><br>function Count() {<br>  // Declare a new state variable, which we&#39;ll call &quot;count&quot;  <br>  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;div&gt;</pre><pre>      &lt;p&gt;You clicked {count} times&lt;/p&gt;</pre><pre>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>        Click me<br>      &lt;/button&gt;</pre><pre>    &lt;/div&gt;<br>  );<br>}</pre><p><strong><em>Before doing anything else. what is the state?</em></strong></p><p>The state<a href="https://medium.com/edonec/state-in-react-an-overview-a182675cee2c"><strong><em> is a plain JavaScript object used by React to represent information about the component’s current situation.</em></strong></a><strong><em> </em></strong><em>that&#39;s mean </em>components use the <strong>state</strong> to create and manage their own data. the component only re-render when the state of the component changes.</p><p>The state is similar to props, but it is private and fully controlled by the component.</p><p>React treats the state as a variable just like any variable declared in a JavaScript function. but the declaration way only changes.</p><pre>// const count = 0; --In JavaScript<br>const [count, setCount] = useState(0);</pre><blockquote>when we call <strong>Count</strong> component, the new state variable <strong>count</strong> is declared. we use <strong>useState() </strong>method to assign the <strong>0 value</strong> to <strong>count state variable.</strong></blockquote><blockquote><strong>useState() </strong>is used to initialize the value to state variable. we can pass any datatype(string/ boolean/ number) values as an argument to useState() method.</blockquote><p>The function returns part look likes here,</p><pre>return (<br>    &lt;div&gt;</pre><pre>         &lt;p&gt;You clicked {count} times&lt;/p&gt;</pre><pre>         &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>                 Click me<br>         &lt;/button&gt;</pre><pre>     &lt;/div&gt;<br>  );</pre><p>Inside the paragraph, we have You clicked {count} times here the value of the count will be shown.</p><p>In the next line of code, when we click the button the setCount() method will be called.</p><pre>&lt;button onClick={() =&gt; setCount(count + 1)}&gt;</pre><pre>// Above function is arrow function that equal to below function</pre><pre>function anyName(){<br>     return setCount(count + 1)<br>}</pre><p><strong>What is the setCount() ?</strong></p><p>If we want to update the <strong>count</strong> state variable value, we can use this <strong>setCount()</strong> method. because the count value is not a fixed value at all times. it can be changed.</p><p><em>***what happen inside the setCount() method?***</em></p><pre>setCount(count + 1)</pre><p>setCount() method takes the current value of count and adds value 1 to the count variable. that’s mean <strong>it is setting the state of the count variable to 1. </strong>if we click again the setCount() method take the current value of count (value 1) and add one to the current value then update the count state value into 2.</p><p><strong>Do you think to implement the whole above statement like this?</strong></p><pre>function Count() {<br><br>  var count = 0;</pre><pre>return (<br>    &lt;div&gt;</pre><pre>        &lt;p&gt;You clicked {count} times&lt;/p&gt;</pre><pre>        &lt;button onClick={() =&gt; count = count + 1}&gt;<br>            Click me<br>        &lt;/button&gt;</pre><pre>    &lt;/div&gt;<br>  );<br>}</pre><p><em>*** Will it work?</em></p><pre>&lt;button onClick={() =&gt; console.log(count); return count = count + 1;}&gt;</pre><p><strong>It changes the value but that does not appear in UI. why?</strong></p><p>When we render something (return something) in React, it renders only one time.</p><p>In our case, when it renders for the first time, the count state variable will be one. when we click the button a second time, the count value is increased but it won’t show the UI because variables by themselves only change bits in memory and do not sync with the view(UI). that’s mean it doesn’t change the state of the component. if we want to change both places(memory and UI), we want to <strong>state hooks </strong>which use to update the state of the component.</p><p>this &lt;p&gt;You clicked {count} times&lt;/p&gt; line of code is not re-rendered.</p><blockquote>***<a href="https://www.w3schools.com/react/react_state.asp">When the </a><a href="https://www.w3schools.com/react/react_state.asp">state object changes, the component re-renders.</a>***</blockquote><p><strong><em>To re-render the element, we need to change the state of the variable.</em></strong><em> </em>that’s why we declare the variable as a state variable and use setState() method to update the state of the variable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a59fc6af5d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>