<?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 Prakshep Goswami on Medium]]></title>
        <description><![CDATA[Stories by Prakshep Goswami on Medium]]></description>
        <link>https://medium.com/@goswamiprakshep9876?source=rss-faf61cd970ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CqQ7XGxrZnQFqRxt</url>
            <title>Stories by Prakshep Goswami on Medium</title>
            <link>https://medium.com/@goswamiprakshep9876?source=rss-faf61cd970ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:11:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goswamiprakshep9876/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[Why Your Queries Lag — But Facebook is Lightning Fast]]></title>
            <link>https://medium.com/@goswamiprakshep9876/why-your-queries-lag-but-facebook-is-lightning-fast-a1838de97f99?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1838de97f99</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[prakshep]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[davv]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Tue, 10 Jun 2025 07:51:23 GMT</pubDate>
            <atom:updated>2025-06-10T07:51:23.422Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Your Queries Lag — But Facebook is Lightning Fast</h3><p>In the world of data and performance, it’s a common experience: you run a SQL query on a large dataset, and it takes several seconds — or even minutes — to return results. Yet, platforms like Facebook can log you in, fetch your data, and display personalized content within milliseconds, even though they deal with billions of users.</p><h3>Traditional SQL Query Execution: Why It’s Often Slow</h3><p>When you run a SQL query like this :</p><pre>SELECT * FROM orders<br>WHERE user_id = 1008<br>AND status = &#39;delivered&#39;;</pre><p>The database engine must:</p><ul><li>Scan the orders table</li><li>Apply filters (user_id, status)</li><li>Possibly join other tables</li><li>Return the result set</li></ul><p>If the table has millions of rows and lacks appropriate indexing or caching, the engine retrieves data <strong>from disk</strong>, processes it, and returns the results. This disk-based operation is inherently slower.</p><p><strong><em>Analogy: This is like searching for a specific file in a huge warehouse without a map.</em></strong></p><figure><img alt="Performance Flowchart" src="https://cdn-images-1.medium.com/max/1024/1*DDwNT2OA7GVnQ9Mon9b4hw.png" /><figcaption>Performance Flowchart</figcaption></figure><h3>Facebook’s Approach: Speed Through Smart Engineering</h3><p>Facebook handles millions of concurrent users with sub-second response times. This performance is made possible by a combination of <strong>in-memory caching</strong>, <strong>data pre-processing</strong>, and <strong>custom infrastructure</strong>.</p><h4>1. In-Memory Caching (Memcached, TAO)</h4><p>Facebook uses <strong>Memcached</strong>, a high-performance, distributed memory object caching system, to store frequently accessed data such as:</p><ul><li>User profiles</li><li>Friend lists</li><li>Session tokens</li></ul><p>For social graph data (e.g., relationships, likes), Facebook developed The Association Object (<strong>TAO</strong>) , an in-memory graph database that handles trillions of relationships with microsecond latency.</p><h4>2. RAM vs Disk</h4><p>RAM access is exponentially faster than disk access. Most user-related data is served from memory rather than from the primary SQL database.</p><h4>3. Cache-First Design</h4><p>Facebook uses a <strong>cache-first strategy</strong>:</p><ul><li>Attempt to serve from cache (Memcached/TAO)</li><li>If cache miss occurs, fall back to MySQL</li><li>Cache the result for next time.</li></ul><blockquote><strong>Analogy: It’s like keeping your most-used files on your desk rather than going to the storage room every time.</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1838de97f99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[884. Uncommon Words from Two Sentences (Leetcode POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/884-uncommon-words-from-two-sentences-leetcode-potd-bdeda7ac17e8?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdeda7ac17e8</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[prakshep]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 18:21:55 GMT</pubDate>
            <atom:updated>2024-09-17T18:21:55.201Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>sentence</strong> is a string of single-space separated words where each word consists only of lowercase letters.</p><p>A word is <strong>uncommon</strong> if it appears exactly once in one of the sentences, and <strong>does not appear</strong> in the other sentence.</p><p>Given two <strong>sentences</strong> s1 and s2, return <em>a list of all the </em><strong><em>uncommon words</em></strong>. You may return the answer in <strong>any order</strong>.</p><p><strong>Example 1:</strong></p><p><strong>Input:</strong> s1 = “this apple is sweet”, s2 = “this apple is sour”</p><p><strong>Output:</strong> [“sweet”,”sour”]</p><p><strong>Explanation:</strong></p><p>The word &quot;sweet&quot; appears only in s1, while the word &quot;sour&quot; appears only in s2.</p><p><strong>Example 2:</strong></p><p><strong>Input:</strong> s1 = “apple apple”, s2 = “banana”</p><p><strong>Output:</strong> [“banana”]</p><pre>class Solution {<br>  public String[] uncommonFromSentences(String A, String B) {<br>    List&lt;String&gt; ans = new ArrayList&lt;&gt;();<br>    Map&lt;String, Integer&gt; count = new HashMap&lt;&gt;();<br><br>    for (final String word : (A + &#39; &#39; + B).split(&quot; &quot;))<br>      count.merge(word, 1, Integer::sum);<br><br>    for (final String word : count.keySet())<br>      if (count.get(word) == 1)<br>        ans.add(word);<br><br>    return ans.toArray(new String[0]);<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdeda7ac17e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Minimize the Heights II (GFG POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/minimize-the-heights-ii-15779f8a24bd?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/15779f8a24bd</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[gfg]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 19:36:13 GMT</pubDate>
            <atom:updated>2024-09-17T18:23:17.175Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an array <strong>arr[]</strong> denoting heights of <strong>N</strong> towers and a positive integer <strong>K.</strong></p><p>For <strong>each </strong>tower, you must perform <strong>exactly one</strong> of the following operations <strong>exactly once</strong>.</p><ul><li><strong>Increase </strong>the height of the tower by <strong>K</strong></li><li><strong>Decrease </strong>the height of the tower by <strong>K</strong></li></ul><p>Find out the <strong>minimum </strong>possible difference between the height of the shortest and tallest towers after you have modified each tower.</p><p>You can find a slight modification of the problem <a href="https://practice.geeksforgeeks.org/problems/minimize-the-heights-i/1/">here</a>.<br><strong>Note:</strong> It is <strong>compulsory </strong>to increase or decrease the height by K for each tower. <strong>After</strong> the operation, the resultant array should <strong>not</strong> contain any <strong>negative integers</strong>.</p><p><strong>Examples :</strong></p><pre>Input: k = 2, arr[] = {1, 5, 8, 10}<br>Output: 5<br>Explanation: The array can be modified as {1+k, 5-k, 8-k, 10-k} = {3, 3, 6, 8}.The difference between the largest and the smallest is 8-3 = 5.</pre><pre>Input: k = 3, arr[] = {3, 9, 12, 16, 20}<br>Output: 11<br>Explanation: The array can be modified as {3+k, 9+k, 12-k, 16-k, 20-k} -&gt; {6, 12, 9, 13, 17}.The difference between the largest and the smallest is 17-6 = 11.</pre><p><strong>Expected Time Complexity:</strong> O(n*logn)<br><strong>Expected Auxiliary Space:</strong> O(n)</p><p><strong>Constraints</strong><br>1 ≤ k ≤ 10^7<br>1 ≤ n ≤ 10^5<br>1 ≤ arr[i] ≤ 10^7</p><pre><br><br>class Solution {<br>    int getMinDiff(int[] arr, int k) {<br>        <br>        int n1 = arr.length;<br>        if (n1 == 1) {<br>            return 0; <br>        }<br>        Arrays.sort(arr);<br>        int differ = arr[n1 - 1] - arr[0];<br>        int smal = arr[0] + k;<br>        int lar = arr[n1 - 1] - k;<br>        for (int i = 0; i &lt; n1 - 1; i++) {<br>            int curr_Max = Math.max(arr[i] + k, arr[n1 - 1] - k);<br>            int curr_Min = Math.min(arr[i + 1] - k, arr[0] + k);<br>            if (curr_Min &lt; 0){<br>                continue;<br>            } <br>            differ = Math.min(differ, curr_Max - curr_Min);<br>        }<br>        return differ;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15779f8a24bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[539. Minimum Time Difference (Leetcode POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/539-minimum-time-difference-leetcode-potd-1edfa69be641?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/1edfa69be641</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 11:05:29 GMT</pubDate>
            <atom:updated>2024-09-16T11:05:29.684Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a list of 24-hour clock time points in <strong>“HH:MM”</strong> format, return <em>the minimum </em><strong><em>minutes</em></strong><em> difference between any two time-points in the list</em>.</p><p><strong>Example 1:</strong></p><pre>Input: timePoints = [&quot;23:59&quot;,&quot;00:00&quot;]<br>Output: 1</pre><p><strong>Example 2:</strong></p><pre>Input: timePoints = [&quot;00:00&quot;,&quot;23:59&quot;,&quot;00:00&quot;]<br>Output: 0</pre><p><strong>Constraints:</strong></p><ul><li>2 &lt;= timePoints.length &lt;= 2 * 10^4</li><li>timePoints[i] is in the format <strong>&quot;HH:MM&quot;</strong>.</li></ul><pre><br>// java solution <br>// prakshep Goswami<br>class Solution {<br>  public int findMinDifference(List&lt;String&gt; timePoints) {<br>    int ans = 24 * 60;<br>    int first = 24 * 60;<br>    boolean[] bucket = new boolean[24 * 60];<br><br>    for (final String timePoint : timePoints) {<br>      final int num =<br>          Integer.valueOf(timePoint.substring(0, 2)) * 60 + Integer.valueOf(timePoint.substring(3));<br>      first = Math.min(first, num);<br>      if (bucket[num])<br>        return 0;<br>      bucket[num] = true;<br>    }<br><br>    int prev = first;<br><br>    for (int i = first + 1; i &lt; bucket.length; ++i)<br>      if (bucket[i]) {<br>        ans = Math.min(ans, i - prev);<br>        prev = i;<br>      }<br><br>    return Math.min(ans, 24 * 60 - prev + first);<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1edfa69be641" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Longest valid Parentheses (GFG POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/longest-valid-parentheses-gfg-potd-288b22af0dbb?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/288b22af0dbb</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[prakshep]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 11:00:41 GMT</pubDate>
            <atom:updated>2024-09-16T11:00:41.316Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a string <strong>str</strong> consisting of opening and closing parenthesis ‘<strong>(</strong>‘ and ‘<strong>)</strong>’. Find length of the longest valid parenthesis substring.</p><p>A parenthesis string is valid if:</p><ul><li>For every opening parenthesis, there is a closing parenthesis.</li><li>Opening parenthesis must be closed in the correct order.</li></ul><p><strong>Examples :</strong></p><pre>Input: str = ((()<br>Output: 2<br>Explaination: The longest valid parenthesis substring is &quot;()&quot;.</pre><pre>Input: str = )()())<br>Output: 4<br>Explaination: The longest valid parenthesis substring is &quot;()()&quot;.</pre><p><strong>Expected Time Complexity:</strong> O(|str|)<br><strong>Expected Auxiliary Space:</strong> O(|str|)</p><p><strong>Constraints:</strong><br>1 ≤ |str| ≤ 10^5</p><pre><br><br>//User function Template for Java<br>// java solution <br>// prakshep Goswami<br><br>class Solution{<br>    static int maxLength(String S){<br>        // code here<br>        int left = 0, right = 0, max = 0;<br>        <br>        for(int i = 0; i &lt; S.length(); i++) {<br>            if(S.charAt(i) == &#39;(&#39;) {<br>                left++;<br>            } else {<br>                right++;<br>            }<br>            <br>            if(left == right) {<br>                max = Math.max(max, left*2);<br>            } else if (right&gt;left) {<br>                left = 0;<br>                right = 0;<br>            }<br>        }<br>        <br>        left = 0;<br>        right = 0;<br>        <br>        for(int i = S.length()-1; i &gt;= 0; i--) {<br>            if(S.charAt(i) == &#39;(&#39;) {<br>                left++;<br>            } else {<br>                right++;<br>            }<br>            <br>            if(left == right) {<br>                max = Math.max(max, left*2);<br>            } else if (left&gt;right) {<br>                left = 0;<br>                right = 0;<br>            }<br>        }<br>        return max;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=288b22af0dbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Tree to DLL (GFG POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/binary-tree-to-dll-gfg-potd-0bbb58d6d958?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bbb58d6d958</guid>
            <category><![CDATA[gfg]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[prakshep]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Sat, 14 Sep 2024 18:56:32 GMT</pubDate>
            <atom:updated>2024-09-14T18:58:28.050Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.geeksforgeeks.org/convert-binary-tree-to-doubly-linked-list-by-keeping-track-of-visited-node/">Convert Binary Tree to Doubly Linked List by keeping track of visited node - GeeksforGeeks</a></p><h3><strong>Binary Tree to DLL (GFG POTD)</strong></h3><p>Given a Binary Tree (BT), convert it to a Doubly Linked List (DLL) in place. The left and right pointers in nodes will be used as previous and next pointers respectively in converted DLL. The <strong>order of nodes</strong> in DLL must be the same as the order of the given Binary Tree. The first node of <strong>Inorder traversal</strong> (leftmost node in BT) must be the head node of the DLL.</p><p><strong>Note: </strong>h is the tree’s height, and this space is used implicitly for the recursion stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*_Qiv9hskqWpa7Iin.png" /><figcaption>GFG Problem of the day 15/09/24</figcaption></figure><p><strong>Examples:</strong></p><pre>Input:<br>      1<br>    /  \<br>   3    2<br>Output:<br>3 1 2 <br>2 1 3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*MHdQsrTMfSbXZCT9.png" /></figure><pre>Explanation: DLL would be 3&lt;=&gt;1&lt;=&gt;2</pre><pre>Input:<br>       10<br>      /   \<br>     20   30<br>   /   \<br>  40   60<br>Output:<br>40 20 60 10 30 <br>30 10 60 20 40</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*WAe3aFCXOcD1UNLT.png" /></figure><pre>Explanation:  DLL would be 40&lt;=&gt;20&lt;=&gt;60&lt;=&gt;10&lt;=&gt;30.</pre><p><strong>Expected Time Complexity: </strong>O(no. of nodes)<br><strong>Expected Space Complexity: </strong>O(height of the tree)</p><p><strong>Constraints:</strong><br>1 ≤ Number of nodes ≤ 105<br>0 ≤ Data of a node ≤ 105</p><pre>// Java Solution<br><br>class Solution<br>{<br>    //Function to convert binary tree to doubly linked list and return it.<br>   void dll(Node root,Node []arr){<br>        if(root==null)<br>        return ;<br>        dll(root.left,arr);<br>        if(arr[1]==null){<br>            arr[1]=root;<br>            arr[0]=root;<br>        }<br>        else {<br>            root.left=arr[0];<br>            arr[0].right=root;<br>            arr[0]=root;<br>        }<br>        dll(root.right,arr);<br>    } <br>    Node bToDLL(Node root)<br>    {<br>  Node []arr={null,null};<br>  dll(root,arr);<br>  return arr[1];<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bbb58d6d958" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2419. Longest Subarray With Maximum Bitwise AND (Leetcode POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/2419-longest-subarray-with-maximum-bitwise-and-leetcode-solution-4edbdec35f9b?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/4edbdec35f9b</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[prakshep]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Sat, 14 Sep 2024 18:39:11 GMT</pubDate>
            <atom:updated>2024-09-14T18:49:18.078Z</atom:updated>
            <content:encoded><![CDATA[<p>You are given an integer array nums of size n.</p><p>Consider a <strong>non-empty</strong> subarray from nums that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p><ul><li>In other words, let k be the maximum value of the bitwise AND of <strong>any</strong> subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.</li></ul><p>Return <em>the length of the </em><strong><em>longest</em></strong><em> such subarray</em>.</p><p>The bitwise AND of an array is the bitwise AND of all the numbers in it.</p><p>A <strong>subarray</strong> is a contiguous sequence of elements within an array.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [1,2,3,3,2,2]<br>Output: 2<br>Explanation:<br>The maximum possible bitwise AND of a subarray is 3.<br>The longest subarray with that value is [3,3], so we return 2.</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [1,2,3,4]<br>Output: 1<br>Explanation:<br>The maximum possible bitwise AND of a subarray is 4.<br>The longest subarray with that value is [4], so we return 1.</pre><p><strong>Constraints:</strong></p><ul><li>1 &lt;= nums.length &lt;= 105</li><li>1 &lt;= nums[i] &lt;= 106</li></ul><pre>// Prakshep Goswami  <br>//java Solution <br><br>class Solution {<br>  public int longestSubarray(int[] nums) {<br>    int ans = 0;<br>    int maxIndex = 0;<br>    int sameNumLength = 0;<br><br>    for (int i = 0; i &lt; nums.length; ++i)<br>      if (nums[i] == nums[maxIndex]) {<br>        ans = Math.max(ans, ++sameNumLength);<br>      } else if (nums[i] &gt; nums[maxIndex]) {<br>        maxIndex = i;<br>        sameNumLength = 1;<br>        ans = 1;<br>      } else {<br>        sameNumLength = 0;<br>      }<br><br>    return ans;<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4edbdec35f9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alternate positive and negative numbers (GFG POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/alternate-positive-and-negative-numbers-gfg-leetcode-4e541cceb7a0?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e541cceb7a0</guid>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Sat, 14 Sep 2024 18:30:01 GMT</pubDate>
            <atom:updated>2024-09-14T19:01:41.944Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.geeksforgeeks.org/problems/array-of-alternate-ve-and-ve-nos1401/1">Alternate positive and negative numbers | Practice | GeeksforGeeks</a></p><h3>Alternate positive and negative numbers (GFG POTD)</h3><p>Given an unsorted array <strong>arr </strong>containing<strong> </strong>both<strong> positive</strong> and <strong>negative</strong> numbers. Your task is to create an array of alternate positive and negative numbers without changing the relative order of positive and negative numbers.</p><p>#Prakshep #goswami #iips #davv</p><p><strong>Note: </strong>Array should start with a positive number and 0 (zero) should be considered a positive element.</p><p><strong>Examples:</strong></p><pre>Input: arr[] = [9, 4, -2, -1, 5, 0, -5, -3, 2]<br>Output: 9 -2 4 -1 5 -5 0 -3 2<br>Explanation: Positive elements : [9,4,5,0,2]<br>Negative elements : [-2,-1,-5,-3]<br>As we need to maintain the relative order of postive elements and negative elements we will pick each element from the positive and negative and will store them. If any of the positive and negative numbersare completed. we will continue with the remaining signed elements.<br>The output is 9,-2,4,-1,5,-5,0,-3,2.</pre><pre>Input: arr[] = [-5, -2, 5, 2, 4, 7, 1, 8, 0, -8]<br>Output: 5 -5 2 -2 4 -8 7 1 8 0<br>Explanation : Positive elements : [5,2,4,7,1,8,0]<br>Negative elements : [-5,-2,-8]<br>The output is 5, -5, 2, -2, 4, -8, 7, 1, 8, 0.</pre><p><strong>Expected Time Complexity:</strong> O(n)<br><strong>Expected Auxiliary Space:</strong> O(n)</p><p><strong>Constraints:</strong><br>1 ≤ arr.size() ≤ 107<br>-106 ≤ arr[i] ≤ 107</p><pre><br>// User function Template for Java<br>// Java Solution<br><br>class Solution {<br>    void rearrange(ArrayList&lt;Integer&gt; arr) {<br>        // code here<br>         Queue&lt;Integer&gt; pNum = new LinkedList&lt;Integer&gt;();<br>        Queue&lt;Integer&gt; nNum = new LinkedList&lt;Integer&gt;();<br>        for(Integer i : arr)<br>        {<br>            if(i &gt;= 0)<br>            {<br>                pNum.add(i);<br>            }<br>            else<br>            {<br>                nNum.add(i);<br>            }<br>        }<br>        arr.clear(); // clear all the elements of arr<br>        while(!pNum.isEmpty() || !nNum.isEmpty())<br>        {<br>            if(!pNum.isEmpty())<br>            {<br>                Integer ele = pNum.poll(); <br>                arr.add(ele);<br>            }<br>            if(!nNum.isEmpty())<br>            {<br>                Integer ele = nNum.poll();<br>                arr.add(ele);<br>            }<br>        }<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e541cceb7a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1684. Count the Number of Consistent Strings (Leetcode]]></title>
            <link>https://medium.com/@goswamiprakshep9876/1684-count-the-number-of-consistent-strings-leetcode-7681cb7c2945?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/7681cb7c2945</guid>
            <category><![CDATA[jav]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Fri, 13 Sep 2024 18:29:55 GMT</pubDate>
            <atom:updated>2024-09-14T19:03:01.887Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://leetcode.com/problems/count-the-number-of-consistent-strings/">1684. Count the Number of Consistent Strings</a> (Leetcode POTD)</h3><p>You are given a string allowed consisting of <strong>distinct</strong> characters and an array of strings words. A string is <strong>consistent </strong>if all characters in the string appear in the string allowed.</p><p>#Prakshep #goswami #iips #davv</p><p>Return<em> the number of </em><strong><em>consistent</em></strong><em> strings in the array </em>words.</p><p><strong>Example 1:</strong></p><pre>Input: allowed = &quot;ab&quot;, words = [&quot;ad&quot;,&quot;bd&quot;,&quot;aaab&quot;,&quot;baa&quot;,&quot;badab&quot;]<br>Output: 2<br>Explanation: Strings &quot;aaab&quot; and &quot;baa&quot; are consistent since they only contain characters &#39;a&#39; and &#39;b&#39;.</pre><p><strong>Example 2:</strong></p><pre>Input: allowed = &quot;abc&quot;, words = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;ab&quot;,&quot;ac&quot;,&quot;bc&quot;,&quot;abc&quot;]<br>Output: 7<br>Explanation: All strings are consistent.</pre><p><strong>Example 3:</strong></p><pre>Input: allowed = &quot;cad&quot;, words = [&quot;cc&quot;,&quot;acd&quot;,&quot;b&quot;,&quot;ba&quot;,&quot;bac&quot;,&quot;bad&quot;,&quot;ac&quot;,&quot;d&quot;]<br>Output: 4<br>Explanation: Strings &quot;cc&quot;, &quot;acd&quot;, &quot;ac&quot;, and &quot;d&quot; are consistent.</pre><p><strong>Constraints:</strong></p><ul><li>1 &lt;= words.length &lt;= 104</li><li>1 &lt;= allowed.length &lt;= 26</li><li>1 &lt;= words[i].length &lt;= 10</li><li>The characters in allowed are <strong>distinct</strong>.</li><li>words[i] and allowed contain only lowercase English letters.</li></ul><pre>// Java Solution <br>class Solution {<br>  public int countConsistentStrings(String allowed, String[] words) {<br>    return (int) Arrays.stream(words)<br>        .filter(word -&gt; word.matches(String.format(&quot;[%s]*&quot;, allowed))) .count();<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7681cb7c2945" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mirror Tree (GFG POTD)]]></title>
            <link>https://medium.com/@goswamiprakshep9876/mirror-tree-gfg-potd-87a2fe68417a?source=rss-faf61cd970ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/87a2fe68417a</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[gfg]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[prakshep]]></category>
            <dc:creator><![CDATA[Prakshep Goswami]]></dc:creator>
            <pubDate>Thu, 12 Sep 2024 18:57:17 GMT</pubDate>
            <atom:updated>2024-09-12T18:57:17.426Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a Binary Tree, convert it into its mirror.</p><p>#Prakshep #goswami #iips #davv</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*bZEH48NO4LUOWBs_.jpg" /><figcaption>Mirror Trees</figcaption></figure><p><strong>Examples:</strong></p><pre>Input:<br>      1<br>    /  \<br>   2    3<br>Output: 3 1 2<br>Explanation: The tree is<br>   1    (mirror)  1<br> /  \    =&gt;      /  \<br>2    3          3    2<br>The inorder of mirror is 3 1 2</pre><pre>Input:<br>      10<br>     /  \<br>    20   30<br>   /  \<br>  40  60<br>Output: 30 10 60 20 40<br>Explanation: The tree is<br>      10               10<br>    /    \  (mirror) /    \<br>   20    30    =&gt;   30    20<br>  /  \                   /   \<br> 40  60                 60   40<br>The inroder traversal of mirror is<br>30 10 60 20 40.</pre><p><strong>Expected Time Complexity: </strong>O(N).<br><strong>Expected Auxiliary Space: </strong>O(Height of the Tree).</p><p><strong>Constraints:</strong><br>1 ≤ Number of nodes ≤ 105<br>1 ≤ Data of a node ≤ 105</p><pre>// java code #prakshep #goswami<br>class Solution {<br>    // Function to convert a binary tree into its mirror tree.<br>    void mirror(Node node) {<br>        <br>        if(node == null)<br>        {<br>            return;<br>        }<br>        <br>        mirror(node.left);<br>        mirror(node.right);<br>        <br>        <br>        Node temp = node.left;<br>        node.left = node.right;<br>        node.right = temp;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87a2fe68417a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>