<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akash Jadhav</title>
    <description>The latest articles on DEV Community by Akash Jadhav (@akashjadhav55).</description>
    <link>https://dev.to/akashjadhav55</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F911925%2F3b843c81-3665-4cbe-87c3-384405bb517f.jpeg</url>
      <title>DEV Community: Akash Jadhav</title>
      <link>https://dev.to/akashjadhav55</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akashjadhav55"/>
    <language>en</language>
    <item>
      <title>Private</title>
      <dc:creator>Akash Jadhav</dc:creator>
      <pubDate>Thu, 28 Nov 2024 05:10:32 +0000</pubDate>
      <link>https://dev.to/akashjadhav55/private-3ii4</link>
      <guid>https://dev.to/akashjadhav55/private-3ii4</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1&amp;gt; Medium To Hard (Graph-Based DP with memoization)&lt;br&gt;
&lt;strong&gt;Problem Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Frankenstein, the alchemist, is on a quest to brew the elixir of life. In his attempts, he combines various ingredients and potions, but he has yet to succeed. Every time he brews something, he meticulously notes down the ingredients and their combinations. &lt;/p&gt;

&lt;p&gt;For instance, when he combines "snakefangs" and "wolfbane", he discovers the "awakening" potion, and he records the recipe as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;awakening = snakefangs + wolfbane
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, when three ingredients are required, he notes the recipe as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;thunderstorm = rain + wind + lightning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In general, the recipe would follow this format:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Potion 1 = Ingredient 1 + Ingredient 2&lt;/li&gt;
&lt;li&gt;Potion 2 = Ingredient 1 + Ingredient 2 + Ingredient 3&lt;/li&gt;
&lt;li&gt;Potion 3 = Ingredient 1 + Ingredient 2 + Ingredient 3 + Ingredient 4&lt;/li&gt;
&lt;li&gt;and so on...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each recipe requires magical orbs to brew. The number of magical orbs needed is equal to the number of ingredients minus one. If a potion is made from several ingredients, the total magical orbs required are the sum of orbs required for each ingredient.&lt;/p&gt;

&lt;p&gt;An ingredient can either be an &lt;em&gt;item&lt;/em&gt; or a &lt;em&gt;potion&lt;/em&gt;. Items are already available, while potions are brewed from ingredients, possibly other potions. In his notes, Frankenstein always lists the result as a potion.&lt;/p&gt;

&lt;p&gt;The problem is that sometimes the same potion can be brewed with different recipes, some requiring fewer magical orbs. Given a potion and Frankenstein's notes, you need to determine the minimum number of magical orbs required to brew that potion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(0 &amp;lt; N &amp;lt; 20) (N is the number of recipes)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first line contains an integer (N) representing the number of recipes.&lt;/li&gt;
&lt;li&gt;The next (N) lines contain strings representing the recipes in the format: &lt;code&gt;PotionName=Ingredient1+Ingredient2+...+IngredientN&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The last line contains the name of the potion that Frankenstein needs to brew.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print a single integer representing the minimum number of magical orbs required to brew the given potion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4
awakening=snakefangs+wolfbane
veritaserum=snakefangs+awakening
dragontonic=snakefangs+velarin
dragontonic=awakening+veritaserum
dragontonic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
In this example, there are two ways to brew &lt;em&gt;dragontonic&lt;/em&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;dragontonic = awakening + veritaserum&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Brewing &lt;em&gt;awakening&lt;/em&gt; requires 1 orb, and brewing &lt;em&gt;veritaserum&lt;/em&gt; requires 1 orb.&lt;/li&gt;
&lt;li&gt;Total orbs required = 1 + 1 = 2 orbs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;dragontonic = snakefangs + velarin&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Brewing &lt;em&gt;snakefangs&lt;/em&gt; and &lt;em&gt;velarin&lt;/em&gt; requires no orbs, as they are both ingredients.&lt;/li&gt;
&lt;li&gt;Total orbs required = 1 orb.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thus, the minimum orbs required is 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
oculus=thunderbrew+jellfish
felix=thunderbrew+pumpkin
wigenweld=thunderbrew+ladybug
wigenweld=oculus+felix
thunderbrew=pumpkin+firefly
maxima=pumpkin+ladybug
wigenweld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
To brew &lt;em&gt;wigenweld&lt;/em&gt; with the minimum number of magical orbs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, brew &lt;em&gt;thunderbrew&lt;/em&gt;, which requires 1 orb.&lt;/li&gt;
&lt;li&gt;Then, brew &lt;em&gt;wigenweld&lt;/em&gt; using &lt;em&gt;thunderbrew + ladybug&lt;/em&gt;, requiring 1 more orb.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thus, the total orbs required is 2.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;em&gt;Answer&lt;/em&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.*;
public class PotionBrewer {

    private static Map&amp;lt;String, List&amp;lt;List&amp;lt;String&amp;gt;&amp;gt;&amp;gt; potionRecipes = new HashMap&amp;lt;&amp;gt;();
    private static Map&amp;lt;String, Integer&amp;gt; potionMemo = new HashMap&amp;lt;&amp;gt;();

    public static void main(String[] args) {
        Scanner inputScanner = new Scanner(System.in);
        int recipeCount = inputScanner.nextInt();
        inputScanner.nextLine(); // Consume the newline

        for (int i = 0; i &amp;lt; recipeCount; i++) {
            String recipeLine = inputScanner.nextLine();
            String[] potionParts = recipeLine.split("=");
            String resultingPotion = potionParts[0];
            String[] requiredIngredients = potionParts[1].split("\\+");

            potionRecipes.putIfAbsent(resultingPotion, new ArrayList&amp;lt;&amp;gt;());
            potionRecipes.get(resultingPotion).add(Arrays.asList(requiredIngredients));
        }

        String targetPotion = inputScanner.nextLine();
        inputScanner.close();

        int minimumOrbs = calculateMinimumOrbs(targetPotion);
        System.out.print(minimumOrbs);
    }

    private static int calculateMinimumOrbs(String potion) {
        if (!potionRecipes.containsKey(potion)) {
            return 0; // Base ingredient requires no orbs
        }

        if (potionMemo.containsKey(potion)) {
            return potionMemo.get(potion);
        }

        int minimumOrbsRequired = Integer.MAX_VALUE;

        for (List&amp;lt;String&amp;gt; recipe : potionRecipes.get(potion)) {
            int currentOrbsRequired = recipe.size() - 1; // Orbs required for this recipe
            for (String ingredient : recipe) {
                currentOrbsRequired += calculateMinimumOrbs(ingredient); // Add orbs for sub-ingredients
            }
            minimumOrbsRequired = Math.min(minimumOrbsRequired, currentOrbsRequired);
        }

        potionMemo.put(potion, minimumOrbsRequired);
        return minimumOrbsRequired;
    };
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2&amp;gt; Easy To Medium (Greedy/string)&lt;/p&gt;

&lt;p&gt;Here's a clean version of the problem statement:&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;Problem: JustifyWords&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given a list of &lt;code&gt;K&lt;/code&gt; words and two integers &lt;code&gt;N&lt;/code&gt; and &lt;code&gt;M&lt;/code&gt;, you are tasked with arranging the words into &lt;code&gt;N&lt;/code&gt; lines following these rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each line can contain no more than &lt;code&gt;M&lt;/code&gt; characters.&lt;/li&gt;
&lt;li&gt;Each word should appear entirely on one line.&lt;/li&gt;
&lt;li&gt;If multiple words are on a line, they should be separated by a single space.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is to determine the maximum number of words that can be arranged within the &lt;code&gt;N&lt;/code&gt; lines of length &lt;code&gt;M&lt;/code&gt;.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(0 &amp;lt; K &amp;lt; 25)&lt;/li&gt;
&lt;li&gt;(0 &amp;lt; N &amp;lt; 10)&lt;/li&gt;
&lt;li&gt;(0 &amp;lt; M &amp;lt; 10)&lt;/li&gt;
&lt;li&gt;Words will contain only lowercase alphabets.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first line consists of an integer &lt;code&gt;K&lt;/code&gt;, representing the total number of words.&lt;/li&gt;
&lt;li&gt;The next &lt;code&gt;K&lt;/code&gt; lines each consist of one word.&lt;/li&gt;
&lt;li&gt;The last line consists of two space-separated integers &lt;code&gt;N&lt;/code&gt; and &lt;code&gt;M&lt;/code&gt;, representing the number of lines and the maximum number of characters per line, respectively.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print a single integer denoting the maximum number of words that can be arranged into the &lt;code&gt;N&lt;/code&gt; lines.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Time Limit:&lt;/strong&gt; 1 second&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
i
hello
how
going
u
whatsapp
help
hmm
5 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have 8 words to arrange in 5 lines, each having a maximum of 5 characters. &lt;/p&gt;

&lt;p&gt;One way to arrange the words to fit the maximum number of words is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;how_i
going
u_hmm
help_
hello_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, 7 words can be fitted. There could be other valid combinations, but we are interested in the maximum number of words that can be accommodated.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
a
is
b
be
it
a
5 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have 6 words to arrange in 5 lines, each with a maximum of 4 characters. One possible arrangement is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a_is
b_be
it_a
____
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, all 6 words can fit, and that is the maximum possible arrangement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Answer&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;bits/stdc++.h&amp;gt;
using namespace std;

int K, N, M;
vector&amp;lt;string&amp;gt; words;
int maxCnt = 0;

void backtrack(int i, vector&amp;lt;int&amp;gt; &amp;amp;lines, int cnt, const vector&amp;lt;string&amp;gt; &amp;amp;w) {
    if(static_cast&amp;lt;size_t&amp;gt;(i) == w.size()) { // Cast i to size_t for comparison
        if(cnt &amp;gt; maxCnt) 
            maxCnt = cnt;
        return;
    }
    if(cnt + (static_cast&amp;lt;int&amp;gt;(w.size()) - i) &amp;lt;= maxCnt) return; // Cast w.size() to int
    for(int j = 0; j &amp;lt; N; j++) {
        if(lines[j] == 0) {
            lines[j] = w[i].size();
            backtrack(i + 1, lines, cnt + 1, w);
            lines[j] = 0;
            break;
        } else {
            if(lines[j] + 1 + static_cast&amp;lt;int&amp;gt;(w[i].size()) &amp;lt;= M) { // Cast w[i].size() to int
                lines[j] += 1 + w[i].size();
                backtrack(i + 1, lines, cnt + 1, w);
                lines[j] -= 1 + w[i].size();
            }
        }
    }
    backtrack(i + 1, lines, cnt, w);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin &amp;gt;&amp;gt; K;
    words.resize(K);
    for(auto &amp;amp;s: words) cin &amp;gt;&amp;gt; s;
    cin &amp;gt;&amp;gt; N &amp;gt;&amp;gt; M;
    vector&amp;lt;string&amp;gt; valid;
    for(auto &amp;amp;s: words) 
        if(static_cast&amp;lt;int&amp;gt;(s.size()) &amp;lt;= M) // Cast s.size() to int
            valid.push_back(s);
    sort(valid.begin(), valid.end(), [&amp;amp;](const string &amp;amp;a, const string &amp;amp;b) -&amp;gt; bool {
        if(a.size() != b.size()) return a.size() &amp;gt; b.size();
        return a &amp;lt; b;
    });
    vector&amp;lt;int&amp;gt; lines(N, 0);
    backtrack(0, lines, 0, valid);
    cout &amp;lt;&amp;lt; maxCnt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3&amp;gt; Hard (Graph)&lt;br&gt;
&lt;strong&gt;BusCount&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the Transportation In-Charge of a reputed company, your responsibility is to ensure that buses are available for every employee and that they arrive on time.  &lt;/p&gt;

&lt;p&gt;Since pandemic restrictions have been lifted, but not completely, the number of people allowed on buses is still limited. Employees have started visiting the office regularly.  &lt;/p&gt;

&lt;p&gt;You are given an &lt;strong&gt;M x M matrix&lt;/strong&gt;, which represents the distance between each location. The value in the &lt;em&gt;i-th&lt;/em&gt; row and &lt;em&gt;j-th&lt;/em&gt; column represents the distance between the &lt;em&gt;i-th&lt;/em&gt; place and the &lt;em&gt;j-th&lt;/em&gt; place. Assume that all locations are connected by roads and that the first location is the office. The distance between the &lt;em&gt;i-th&lt;/em&gt; place and the &lt;em&gt;j-th&lt;/em&gt; place is the same as the distance between the &lt;em&gt;j-th&lt;/em&gt; place and the &lt;em&gt;i-th&lt;/em&gt; place. The top-left element of this matrix (0, 0) is the office location.  &lt;/p&gt;

&lt;p&gt;The number of people boarding the bus at each location is known a priori and is part of the input.  &lt;/p&gt;

&lt;p&gt;Given the number of people that a bus can accommodate at one time (post restrictions), determine the number of buses required to pick up all employees. A bus can start from any location but must take only the shortest path from that location to the office. The bus can pick up employees at locations along its route. Assume that there is only one shortest route between the office and each remaining location.  &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;( 1 &amp;lt; M &amp;lt; 12 )
&lt;/li&gt;
&lt;li&gt;( 0 \leq \text{Distance between locations} \leq 300 )
&lt;/li&gt;
&lt;li&gt;( 0 \leq \text{Total number of employees} \leq 500 )
&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First line consists of a single integer ( M ), representing the number of locations including the office.
&lt;/li&gt;
&lt;li&gt;Next ( M ) lines consist of ( M ) integers separated by space, representing the distance matrix.
&lt;/li&gt;
&lt;li&gt;Next line consists of ( M-1 ) space-separated integers, representing the number of employees boarding at each corresponding location.
&lt;/li&gt;
&lt;li&gt;Last line consists of an integer representing the number of people that can travel in the bus at one time.
&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Print a single integer representing the &lt;strong&gt;minimum number of buses required&lt;/strong&gt; to pick up all employees.  &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Time Limit (secs)&lt;/strong&gt;  &lt;/p&gt;
&lt;h2&gt;
  
  
  1
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4  
0 10 10 30  
10 0 30 20  
10 30 0 10  
30 20 10 0  
23 52 11  
25  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The below diagram represents the above input.  &lt;/p&gt;

&lt;p&gt;&lt;a href="" class="article-body-image-wrapper"&gt;&lt;img alt="Distance and Employee Diagram"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Based on the input, there are four locations, which we can denote as 0, 1, 2, and 3. The first location is the office, represented as (0).  &lt;/p&gt;

&lt;p&gt;The shortest paths between each location and the office are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Location 1 → Office&lt;/li&gt;
&lt;li&gt;Location 2 → Office&lt;/li&gt;
&lt;li&gt;Location 3 → Location 2 → Office
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The number of buses required will be 4:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One bus from Location 1&lt;/li&gt;
&lt;li&gt;Two buses from Location 2&lt;/li&gt;
&lt;li&gt;One bus from Location 3
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The two buses start from Location 2. One bus picks up a full load from Location 2 and heads to the office, and the remaining two people board the bus coming from Location 3.  &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5  
0 10 10 60 60  
10 0 30 10 10  
10 30 0 30 30  
60 10 30 0 30  
60 10 30 30 0  
15 15 15 15  
25  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
For this example, the following diagram (not shown) would depict only the shortest path from each location to the office. Three buses will originate from locations 2, 3, and 4 respectively. The buses starting from locations 3 and 4 will need to travel through location 1. Since they have enough seats to pick up the employees from location 1, three buses are sufficient. Therefore, the output is 3.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Answer&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.*; 

public class Main { 
    static int[][] distances; 
    static int[] employees; 
    static int M, busCapacity; 
    static List&amp;lt;Integer&amp;gt;[] shortestPaths; 
    static int[][] nextNode; 

    public static void main(String[] args) { 
        Scanner scanner = new Scanner(System.in); 

        // Read input 
        M = scanner.nextInt(); 
        distances = new int[M][M]; 

        // Read distance matrix 
        for (int i = 0; i &amp;lt; M; i++) { 
            for (int j = 0; j &amp;lt; M; j++) { 
                distances[i][j] = scanner.nextInt(); 
            } 
        } 

        // Read employees at each location (excluding office) 
        employees = new int[M]; 
        for (int i = 1; i &amp;lt; M; i++) { 
            employees[i] = scanner.nextInt(); 
        } 

        // Read bus capacity 
        busCapacity = scanner.nextInt(); 

        // Calculate result 
        int result = solve(); 
        System.out.println(result); 
    } 

    static int solve() { 
        // Find all shortest paths using Floyd-Warshall 
        int[][] dist = floydWarshall(); 
        findShortestPaths(); 

        // Calculate required buses using greedy approach 
        return calculateRequiredBuses(); 
    } 

    static int[][] floydWarshall() { 
        int[][] dist = new int[M][M]; 
        nextNode = new int[M][M]; 

        // Initialize distances and next array 
        for (int i = 0; i &amp;lt; M; i++) { 
            for (int j = 0; j &amp;lt; M; j++) { 
                dist[i][j] = distances[i][j]; 
                if (distances[i][j] != 0) { 
                    nextNode[i][j] = j; 
                } else { 
                    nextNode[i][j] = -1; 
                } 
            } 
        } 

        // Floyd-Warshall algorithm 
        for (int k = 0; k &amp;lt; M; k++) { 
            for (int i = 0; i &amp;lt; M; i++) { 
                for (int j = 0; j &amp;lt; M; j++) { 
                    if (dist[i][k] != 0 &amp;amp;&amp;amp; dist[k][j] != 0 &amp;amp;&amp;amp;  
                        (dist[i][j] == 0 || dist[i][k] + dist[k][j] &amp;lt; dist[i][j])) { 
                        dist[i][j] = dist[i][k] + dist[k][j]; 
                        nextNode[i][j] = nextNode[i][k]; 
                    } 
                } 
            } 
        } 
        return dist; 
    } 

    static void findShortestPaths() { 
        shortestPaths = new List[M]; 
        for (int i = 0; i &amp;lt; M; i++) { 
            shortestPaths[i] = new ArrayList&amp;lt;&amp;gt;(); 
            if (i != 0) { // Skip office 
                int current = i; 
                while (current != 0) { 
                    shortestPaths[i].add(current); 
                    current = nextNode[current][0]; 
                } 
                shortestPaths[i].add(0); // Add office 
            } 
        } 
    } 

    static int calculateRequiredBuses() { 
        int totalBuses = 0; 
        int[] remainingEmployees = Arrays.copyOf(employees, employees.length); 

        // Process locations in order of distance from office (farthest first) 
        List&amp;lt;Integer&amp;gt; locations = new ArrayList&amp;lt;&amp;gt;(); 
        for (int i = 1; i &amp;lt; M; i++) { 
            locations.add(i); 
        } 
        locations.sort((a, b) -&amp;gt; shortestPaths[b].size() - shortestPaths[a].size()); 

        for (int location : locations) { 
            while (remainingEmployees[location] &amp;gt; 0) { 
                // Start a new bus 
                totalBuses++; 
                int capacity = busCapacity; 

                // Pick up employees along the path 
                for (int stop : shortestPaths[location]) { 
                    int canPickup = Math.min(remainingEmployees[stop], capacity); 
                    remainingEmployees[stop] -= canPickup; 
                    capacity -= canPickup; 
                } 
            } 
        } 

        return totalBuses; 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4&amp;gt; Medium (2d Matrix)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Block Extraction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Aarya is playing with LEGO bricks, each a one-unit square. She connects the bricks to form various shapes, creating what is known as a block. Thus, a block is an amalgamation of bricks in four possible directions: top, bottom, left, and right.&lt;/p&gt;

&lt;p&gt;Each such block she created is assigned a unique identity number. Using the blocks she created, Aarya assembled a matrix with dimensions ( N \times M ). This matrix is positioned upright on the ground. Now, Aarya wants to pick up the block numbered ( K ) from the matrix, starting from the top. The rules to pick up the desired block are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A block can be easily removed only if there are no other blocks on top of it.&lt;/li&gt;
&lt;li&gt;It is guaranteed that there are no empty spaces within the matrix.&lt;/li&gt;
&lt;li&gt;If block ( K ) is partially inside block ( L ) and can't be picked directly from the top, she will need to remove block ( L ).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A careful look at the matrix tells us that apart from block ( K ), all other blocks will need to be removed to pick block ( K ).&lt;/p&gt;

&lt;p&gt;To collect a block, we need to understand it as collecting all blocks with the same identity. A block numbered ( K ) may span across multiple rows. To pick up all blocks with identity ( K ), Aarya needs to remove all blocks stacked above any occurrence of ( K ).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first line consists of two space-separated integers, denoting ( N ) and ( M ) (the number of rows and columns of the matrix).&lt;/li&gt;
&lt;li&gt;The next ( N ) lines consist of ( M ) space-separated integers denoting the front view of the matrix assembled by Aarya.&lt;/li&gt;
&lt;li&gt;The last line consists of an integer ( K ), denoting the identity number of the block which Aarya wants to pick up, from the top of the matrix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print a single integer denoting the number of blocks she needs to remove to pick up the block with identity ( K ).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Examples&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Example 1:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 5
7 7 8 8 2
4 4 4 2 2
1 3 3 9 9
1 1 1 5 5
6 6 1 1 1
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The matrix is 5 rows and 5 columns.&lt;/li&gt;
&lt;li&gt;It is composed of blocks with identities 1, 2, 3, 4, 5, 6, 7, 8, and 9.&lt;/li&gt;
&lt;li&gt;Aarya wishes to collect all blocks with identity 1. Block 1 spans across 3 rows (rows 3, 4, and 5).&lt;/li&gt;
&lt;li&gt;To collect block 1, we must remove all blocks stacked above it.&lt;/li&gt;
&lt;li&gt;The blocks to be removed are 2, 3, 4, 5, 7, 8, and 9, resulting in 7 blocks being removed.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Example 2:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6 3
1 1 1
2 2 2
2 3 3
2 2 2
4 5 6
7 7 7
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The matrix is 6 rows and 3 columns, composed of blocks with identities 1, 2, 3, 4, 5, 6, and 7.&lt;/li&gt;
&lt;li&gt;Aarya wishes to collect all blocks with identity 6. Block 6 appears in row 5.&lt;/li&gt;
&lt;li&gt;To collect block 6, we must remove all blocks stacked above it. These are blocks 1, 2, and 3.&lt;/li&gt;
&lt;li&gt;Therefore, the number of blocks to be removed is 3.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Example 3:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4 6
1 1 6 6 6 7
2 3 3 3 8 3
3 3 5 3 3 3
4 9 9 14 14 14
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The matrix is 4 rows and 6 columns.&lt;/li&gt;
&lt;li&gt;It is composed of blocks with identities 1, 2, 3, 5, 6, 7, 8, 9, and 14.&lt;/li&gt;
&lt;li&gt;Aarya wishes to collect all blocks with identity 5. Block 5 appears in the third row.&lt;/li&gt;
&lt;li&gt;To collect block 5, we must remove all the blocks stacked above it. These are blocks numbered 1, 2, 3, 6, 7, and 8.&lt;/li&gt;
&lt;li&gt;Therefore, the number of blocks to be removed is 6.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Constraints:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;( 0 \leq ) number of blocks ( \leq 500 )&lt;/li&gt;
&lt;li&gt;( 1 \leq N, M \leq 50 )&lt;/li&gt;
&lt;li&gt;A block will never be fully enclosed by another block, meaning it won't be surrounded on all four sides.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This concludes the complete problem statement with three examples. Let me know if anything else is required!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Deploy a json-server on render</title>
      <dc:creator>Akash Jadhav</dc:creator>
      <pubDate>Fri, 15 Nov 2024 12:15:22 +0000</pubDate>
      <link>https://dev.to/akashjadhav55/how-to-deploy-a-json-server-on-render-3h8l</link>
      <guid>https://dev.to/akashjadhav55/how-to-deploy-a-json-server-on-render-3h8l</guid>
      <description>&lt;p&gt;A short step by step by step guide to creating a JSON-DB server and deploying it on render&lt;br&gt;
json-server is a tool for creating mock REST API fast! To get started, ensure you have the following requirements:&lt;/p&gt;

&lt;p&gt;NodeJS (npm)&lt;br&gt;
Let's get started!&lt;/p&gt;

&lt;p&gt;On an empty folder, initiate a nodejs application by running the following on your terminal/CMD:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once that is complete, you install the following packages:&lt;br&gt;
`&lt;br&gt;
json-server&lt;/p&gt;

&lt;p&gt;json-serve&lt;/p&gt;

&lt;p&gt;cors&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install json-server json-serve cors&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After the installation, create a new file: index.js. This is the entry point for the json-serve. Add the following inside the file:&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
const jsonServer = require("json-server"); // importing json-server library&lt;br&gt;
const server = jsonServer.create();&lt;br&gt;
const router = jsonServer.router("db.json");&lt;br&gt;
const middlewares = jsonServer.defaults();&lt;br&gt;
const port = process.env.PORT || 3001; // you can use any port number here; i chose to use 3001&lt;/p&gt;

&lt;p&gt;server.use(middlewares);&lt;br&gt;
server.use(router);&lt;/p&gt;

&lt;p&gt;server.listen(port);&lt;br&gt;
`&lt;br&gt;
In the code above, a server has been created that will be fetching and updating data from a json file, db.json&lt;/p&gt;

&lt;p&gt;In the project root, create a new file: db.json and add the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
{&lt;br&gt;
    "feedback": [&lt;br&gt;
        {&lt;br&gt;
            "id": 1,&lt;br&gt;
            "rating": 10,&lt;br&gt;
            "user_name": "Tony Stark",&lt;br&gt;
            "text": "You are the ironman of this world"&lt;br&gt;
        },&lt;br&gt;
        {&lt;br&gt;
            "id": 2,&lt;br&gt;
            "rating": 9,&lt;br&gt;
            "user_name": "Bruce Wayne",&lt;br&gt;
            "text": "You are the batman of this world"&lt;br&gt;
        },&lt;br&gt;
        {&lt;br&gt;
            "id": 3,&lt;br&gt;
            "rating": 8,&lt;br&gt;
            "user_name": "Peter Parker",&lt;br&gt;
            "text": "You are the spiderman of this world"&lt;br&gt;
        }&lt;br&gt;
    ]&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The mock server is ready to run, but let's add some scripts in package.json:&lt;/p&gt;

&lt;p&gt;Update the "scripts" to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
  "scripts": {&lt;br&gt;
    "start": "node index.js"&lt;br&gt;
  },&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Deploy On Render :-&lt;br&gt;
Go To Site :- &lt;a href="https://dashboard.render.com/" rel="noopener noreferrer"&gt;https://dashboard.render.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select Web Services&lt;br&gt;
&lt;a href="https://dev.tourl"&gt;&lt;/a&gt;&lt;br&gt;
Connect with Github&lt;/p&gt;

&lt;p&gt;Go to Github create new repo&lt;/p&gt;

&lt;p&gt;Clone this repo and create all files and installation of json-server all are mentioned in above.&lt;/p&gt;

&lt;p&gt;push all the code on Github&lt;/p&gt;

&lt;p&gt;Go To Render And Select Github Repo where push all json-server code&lt;/p&gt;

&lt;p&gt;Click on create Web Service Button below&lt;/p&gt;

&lt;p&gt;and wait few minutes for progress and enjoy&lt;/p&gt;

&lt;p&gt;Hopefully this article useful for you , happy coding! || Like this article ♥&lt;/p&gt;

</description>
      <category>aws</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Changes to Replit's Starter Plan: Announced Friday</title>
      <dc:creator>Akash Jadhav</dc:creator>
      <pubDate>Sat, 31 Aug 2024 04:08:17 +0000</pubDate>
      <link>https://dev.to/akashjadhav55/changes-to-replits-starter-plan-announced-friday-46ij</link>
      <guid>https://dev.to/akashjadhav55/changes-to-replits-starter-plan-announced-friday-46ij</guid>
      <description>&lt;p&gt;replit some upcoming changes to your Starter plan:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Changing?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Number of Repls:&lt;/strong&gt; The Starter plan will now have a limit of 3 Repls. To access unlimited* Repls, consider upgrading to the Core plan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration Limits:&lt;/strong&gt; The Starter plan allows 1 collaborator per account. The Core plan allows up to 3 collaborators, while the Teams plan provides access for your entire organization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage Retention:&lt;/strong&gt; Repls on the Starter plan may be deleted after 1 year of inactivity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployments:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Starter plan users can deploy a single static site without needing a credit card (with a 1 GiB outbound data transfer limit). This update will roll out in the next few weeks.&lt;/li&gt;
&lt;li&gt;Autoscale, Reserved VM, and Scheduled Deployments will now require a Core account. If you currently use these features, you'll receive a separate email with further details.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Development:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Development Time:&lt;/strong&gt; The Starter plan will be limited to 600 development minutes per month. To remove this limitation, consider upgrading to the Core plan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outbound Data Transfer:&lt;/strong&gt; The Starter plan will have a new outbound data transfer limit of 1 GiB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Development Storage:&lt;/strong&gt; The storage limit on the Starter plan will change to 2 GiBs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;These changes will take effect fully on August 26th.&lt;/p&gt;

</description>
      <category>replit</category>
      <category>news</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
