<?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 jatin grover on Medium]]></title>
        <description><![CDATA[Stories by jatin grover on Medium]]></description>
        <link>https://medium.com/@jatingrover1358?source=rss-30459a84ac30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OLnOKENYPZYUlc-P.jpg</url>
            <title>Stories by jatin grover on Medium</title>
            <link>https://medium.com/@jatingrover1358?source=rss-30459a84ac30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:10:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jatingrover1358/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[Divide Integers]]></title>
            <link>https://medium.com/@jatingrover1358/divide-integers-918cca01419?source=rss-30459a84ac30------2</link>
            <guid isPermaLink="false">https://medium.com/p/918cca01419</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[divide]]></category>
            <category><![CDATA[bit-manipulation]]></category>
            <category><![CDATA[divide-integers]]></category>
            <category><![CDATA[interviewbit]]></category>
            <dc:creator><![CDATA[jatin grover]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 03:41:24 GMT</pubDate>
            <atom:updated>2019-11-19T04:18:27.796Z</atom:updated>
            <content:encoded><![CDATA[<p>Divide two integers without using multiplication, division and mod operator.</p><p>Return the floor of the result of the division.</p><p><strong>Example:</strong></p><pre>5 / 2 = 2</pre><p><strong>Also, consider if there can be overflow cases. For overflow case, return INT_MAX.</strong></p><h3><strong>SOLUTION :</strong></h3><p>We’ll use subtraction to achieve our goal. We’ll continuously deduct (divisor * 2^i) from the dividend till it is possible.</p><blockquote><strong>Eg. a=10 , b=3;</strong></blockquote><blockquote>10–(3*2⁰) =7 -&gt; 3¹ is valid</blockquote><blockquote>10–(3*2¹)= 4 -&gt; 3² is valid</blockquote><blockquote>10-(3*2²)= -2 -&gt; 3³ is not valid</blockquote><blockquote>so we are left with a= (10–6=4)</blockquote><blockquote>repeat same steps for 4 until a ≥ b.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*TblupvwCuRkiqlLAThOBpg.png" /><figcaption>JAVA CODE</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=918cca01419" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Find Duplicate in Array]]></title>
            <link>https://medium.com/@jatingrover1358/find-duplicate-in-array-cc0821e172e7?source=rss-30459a84ac30------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc0821e172e7</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[jatin grover]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 19:06:55 GMT</pubDate>
            <atom:updated>2019-10-07T19:06:55.196Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a read-only array of n + 1 integers between 1 and n, find one number that repeats in linear time using less than O(n) space and traversing the stream sequentially O(1) times.</p><p><strong>Sample Input:</strong></p><pre>[3 4 1 4 1]</pre><p><strong>Sample Output:</strong></p><pre>1</pre><p>If there are multiple possible answers ( like in the sample case above ), output anyone.</p><p>If there is no duplicate, output -1</p><h3>Solution:</h3><p>Please try the underlying problem if you haven’t tried before going on to this question.</p><p><a href="https://www.geeksforgeeks.org/detect-loop-in-a-linked-list/">Detect loop in a linked list - GeeksforGeeks</a></p><p>Steps:</p><ol><li>Create a slow(1 jump) and a fast pointer(2 jump). Where slow pointer goes to A[slow] position whereas fast pointer goes to A[A[fast]].</li><li>If they both meet that means there are duplicates in the array.</li><li>Initialize slow =0;</li><li>Then move slow and fast pointer as one jump; till the time they both collide.</li></ol><p><strong>Code:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*Q-CeJ7DbuPNeXUa6Dbf6JA.png" /><figcaption>Java code</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc0821e172e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximum Unsorted Subarray]]></title>
            <link>https://medium.com/@jatingrover1358/maximum-unsorted-subarray-e186bbf2d40e?source=rss-30459a84ac30------2</link>
            <guid isPermaLink="false">https://medium.com/p/e186bbf2d40e</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[jatin grover]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 18:35:54 GMT</pubDate>
            <atom:updated>2021-12-08T10:45:26.119Z</atom:updated>
            <content:encoded><![CDATA[<p>You are given an array (zero-indexed) of <strong>N</strong> non-negative integers, <strong>A0</strong>, <strong>A1</strong> ,…, <strong>AN-1</strong>.<br>Find the minimum sub-array <strong>Al</strong>, <strong>Al+1</strong> ,…, <strong>Ar</strong> so if we sort(in ascending order) that sub-array, then the whole array should get sorted.<br>If <strong>A</strong> is already sorted, output <strong>-1</strong>.</p><p><strong>Example :</strong></p><pre>Input 1:</pre><pre>A = [1, 3, 2, 4, 5]</pre><pre>Return: [1, 2]</pre><pre>Input 2:</pre><pre>A = [1, 2, 3, 4, 5]</pre><pre>Return: [-1]</pre><h3>Solution:</h3><p><strong>Steps:</strong></p><ol><li>Find the first fluctuation going from left to right (“lpos”)</li><li>Find the first fluctuation going from right to left (“rpos”)</li><li>If no fluctuations return -1;</li><li>Find “min” and “max” between “lpos” and “rpos”.</li><li>Check the index from 0 to “lpos” which is having a value greater than the value at “min”. That index will be new “lpos”.</li><li>Check index from “rpos+1” to n-1 which is having a value less than the value at “max”. That index will be new “rpos”.</li><li>Return “lpos” and “rpos”.</li></ol><h3>Code:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*aVc_fw0l732iy8gcTQAtrA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e186bbf2d40e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Graph Data Structure:]]></title>
            <link>https://medium.com/@jatingrover1358/graph-data-structure-6a9439fdd3da?source=rss-30459a84ac30------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a9439fdd3da</guid>
            <category><![CDATA[interviewbit]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[smallest-multiple]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[jatin grover]]></dc:creator>
            <pubDate>Thu, 12 Sep 2019 18:40:19 GMT</pubDate>
            <atom:updated>2019-09-12T18:59:18.055Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Question:</strong> You are given an integer N. You have to find the smallest multiple of N which consists of digits 0 and 1 only. Since this multiple could be large, return it in the form of a string.</p><p><strong>Note</strong>:</p><p>The returned string should not contain leading zeroes.</p><p>For example,</p><p>For N = 55, 110 is smallest multiple consisting of digits 0 and 1.<br>For N = 2, 10 is the answer.</p><h3>Solution:</h3><p>Checking all the binary numbers will take a lot of time. Is there any way to avoid unnecessary traversals? Yes, we can do this!! The idea we can start with number ‘1’ and appending ‘0’ and ‘1’ to ‘1’. Repeating the steps for the generated number unless we get the required number. (BFS) If we encounter any number which generates the same remainder which is already generated we’ll not take that number and its further states. The whole point is if there are two numbers(a,b) who generate the same remainder; then if on appending ‘1’ or ‘0’ to b, makes it divisible then on appending the same number to ‘a’, will also make it divisible. So we can avoid ‘b’ as we want the smallest one.</p><p><strong>Code 1:</strong></p><figure><img alt="Code 1" src="https://cdn-images-1.medium.com/max/555/1*MuVfnGJPGpzeUJHnEnyvXg.png" /><figcaption><strong>“Java Code 1”</strong></figcaption></figure><p><strong>Code 2:</strong></p><p>The above code is still less efficient. We’ll knock off storing the full number and then calculating the mod. We’ll use the mod to calculate if the state is divisible and then we’ll backtrack to construct number. Below is the code snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*tGOstR5WTcAYKzavXFlVQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*9U-0b9wX-zWYaBPPoHYJoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Pko3TwWFmnoekdlIURP-Kw.png" /><figcaption><strong>“Java Code 2”</strong></figcaption></figure><blockquote>System.out.println(“Thank you for reading.”)</blockquote><blockquote>System.out.println(“Happy coding!!”);</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a9439fdd3da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ways To Decode]]></title>
            <link>https://medium.com/@jatingrover1358/ways-to-decode-8dda6ae2f6a0?source=rss-30459a84ac30------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dda6ae2f6a0</guid>
            <category><![CDATA[decode]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[jatin grover]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 21:20:32 GMT</pubDate>
            <atom:updated>2019-08-18T11:51:09.829Z</atom:updated>
            <content:encoded><![CDATA[<p>A message containing letters from A-Z is being encoded to numbers from 1 to 26. Given an encoded message containing digits, determine the total number of ways to decode it.</p><p><strong>Example :</strong></p><p>Given encoded message &quot;12&quot;, it could be decoded as &quot;AB&quot; (1 2) or &quot;L&quot; (12).The number of ways decoding &quot;12&quot; is 2.</p><h3><strong>Solution:</strong></h3><p>Yes, we can do this recursively but it will take exponential time, so will go with the DP solution. We’ll use an array to store the state of subproblems so that it can be used to solve the bigger problem.</p><figure><img alt="Java Solution Code" src="https://cdn-images-1.medium.com/max/696/1*RccxEPb6qLxOjijfFDLCQQ.png" /><figcaption><strong>“Java Code”</strong></figcaption></figure><p><strong>Initialize:</strong> We’ll take a count array to store the variations of the substrings. We’ll initialize the 0th position of the array as 1. And the 1st position as 1 if the number is greater than 0. The conditional check is just to handle the case if the first character itself is 0. For substring ”1”, count of variations will be count[1].</p><blockquote><strong>Explanation:</strong></blockquote><blockquote>The whole idea is that if the character(c) is valid so on joining it to all variations of the substring(s = 0 to ((index of c) - 1) ) it’s variation count will be the same as of the s. If c is concatenated with the previous character(p) and becomes a valid number then add variations of the substring(0 to ((index of p) -1)) to variations of c.</blockquote><blockquote>e.g “1223”</blockquote><blockquote><em>a. 3’s variations are =&gt; {{1,2,2},{12,2},{1,12}} + {3}[count = 3]</em></blockquote><blockquote><em>b. 23’s variations are =&gt; {{1,2},{12}} + {23} [count = 2]</em></blockquote><blockquote><em>c. Total count = 5.</em></blockquote><p><strong>Note :</strong> substring(begin,end) = inclusive of begin and end. [but not in the code]</p><h4><strong>Dry Run: [A =”1252&quot;]</strong></h4><ol><li>count={1,1,0,0,0}</li><li>2 is valid so add the variations of previous substring(0,0 = 1) i.e. c[1] to c[2]. count={1,1,1,0,0}. We’ll check for 12 now. As this is also valid, we’ll add the varations of substring(0,-1 = null ) i.e. c[0] to c[2]. count={1,1,2,0,0}.</li><li>5 is valid so add the variations of previous substring(0,1 = 12) i.e. c[2] to c[3]. count={1,1,2,2,0}. We’ll check for 25 now. As this is also valid, we’ll add the varations of substring(0,0 = 1) i.e. c[1] to c[3]. count={1,1,2,3,0}</li><li>2 is valid so add the variations of previous substring(0,2 = 125) i.e c[3] to c[4]. count={1,1,2,3,3}. We’ll check for 52, which is not valid.</li><li>return c[4] i.e. count of substring(0,3 = “1252&quot;) i.e. 3.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dda6ae2f6a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>