<?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 pyRovks on Medium]]></title>
        <description><![CDATA[Stories by pyRovks on Medium]]></description>
        <link>https://medium.com/@lordrovks?source=rss-152d524f3178------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RoWzQjhQxj0GM1mA</url>
            <title>Stories by pyRovks on Medium</title>
            <link>https://medium.com/@lordrovks?source=rss-152d524f3178------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:13:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lordrovks/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[Code Snippet and explanation]]></title>
            <link>https://medium.com/@lordrovks/code-snippet-and-explanation-a063348d126?source=rss-152d524f3178------2</link>
            <guid isPermaLink="false">https://medium.com/p/a063348d126</guid>
            <dc:creator><![CDATA[pyRovks]]></dc:creator>
            <pubDate>Mon, 24 Jul 2023 04:24:31 GMT</pubDate>
            <atom:updated>2023-07-25T04:11:00.802Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Code Snippet and explanation ll</strong></p><p>We can reframe our problem statement to an algorithmic task — “Given an array with non-negative elements, split it into K sub-arrays such that the maximum sum of all sub-arrays is minimum.”</p><p><em>Example — Input : Array[] = {1, 2, 3, 4}, K = 3</em></p><ol><li><strong><em>best case:</em></strong><em><br>Optimal bucket size: 4 [i.e at max we can have a total of 4 records in a bucket] <br>Optimal split: {1, 2}, {3}, {4}, here the maximum sum of all subarrays is 4 [which in this case is minimum] given k=3</em></li><li><strong><em>non-optimal case:<br></em></strong><em>bucket size: 5<br>bucket split: {1}, {2,3}, {4} -&gt; Over here maximum sum of all subarrays is 5 [non-optimal case as there is a possibility of even lower value]</em></li></ol><p><strong>Naive approach:</strong></p><ol><li>A naive approach would be to find all possibilities of k such sub-arrays using backtracking.</li><li>Find the sum of the sub-array and take the case where the sum of those k sub-arrays is minimum.</li><li>This approach has a very high time complexity and would be extremely slow if the array size is large.</li></ol><p><strong>Our Approach — the efficient one :</strong></p><p><em>[Step — 1] </em>The idea is to use a binary search algorithm to find the optimal bucket size [i.e the maximum records we can have in a bucket] such that it is minimum. The range of the search is defined by the lowest and highest possible values where,</p><blockquote>the lowest value would be the max element of the array, when the no of buckets is equal to the size of the array i.e <strong>k=n</strong>. Here we can allot the max element to one bucket and divide the other sections such that the sum of those sub-array is less than or equal to max.</blockquote><blockquote>the highest value would be the sum of all the elements in the array and this happens when we allot all the records of the array to one bucket i.e <strong>k=1</strong></blockquote><p>Then in each iteration, we try to get the minimum possible value of <em>mid</em> which satisfies the condition</p><blockquote>Condition -&gt; no of bucket counts we get using the mid value as our bucket size should be less than the actual <em>k, </em>and it should cover all the array’s element</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/649f215a3e5e2a413c7c2122e2c4d6cd/href">https://medium.com/media/649f215a3e5e2a413c7c2122e2c4d6cd/href</a></iframe><p><em>[Step — 2] </em>Then partition the array records into <strong><em>k</em></strong> buckets once we get the optimal size of the bucket such that the distribution metric [i.e sum of the records of each bucket] is more or less the same. Then returns the dictionary which contains the partitioned records.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4a46f6296f31c620c115d11a07b638f/href">https://medium.com/media/b4a46f6296f31c620c115d11a07b638f/href</a></iframe><p><em>[Step — 3]</em> We also have a useful function to get the best<strong><em> k</em></strong> value just for exploration. <strong><em>k</em></strong><em> value affects the parallelization of the flow and is usually decided based on the computing resource constraints.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70841a64db914fdf09ce1c30c6ff7f4e/href">https://medium.com/media/70841a64db914fdf09ce1c30c6ff7f4e/href</a></iframe><p>We have wrapped the above relevant methods as a module along with other utility functions.</p><pre>Use pip to install our module <br><br>$pip install wm_flow_creation</pre><p>Below is the driver code to use our module to partition an array of records into <strong><em>k</em></strong> buckets.</p><p>Use case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d8e6363320f96392388496e3321875b/href">https://medium.com/media/1d8e6363320f96392388496e3321875b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Bp5GrtxNGSY_t3-zXPP8w.png" /><figcaption>Flowchart of the Algorithm</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*XUeVw_1hoUkS7ge74ab1oA.png" /><figcaption>Binary Seach Algorithm to find the Optimal Bucket size</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a063348d126" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>