<?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 Parag Naik on Medium]]></title>
        <description><![CDATA[Stories by Parag Naik on Medium]]></description>
        <link>https://medium.com/@paragnaik2019?source=rss-198f075d206c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qvK3_TITj0KzZUbn.jpg</url>
            <title>Stories by Parag Naik on Medium</title>
            <link>https://medium.com/@paragnaik2019?source=rss-198f075d206c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:15:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paragnaik2019/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[Exploring Tree-Inorder Traversal]]></title>
            <link>https://paragnaik2019.medium.com/exploring-tree-inorder-traversal-70250862d5b1?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/70250862d5b1</guid>
            <category><![CDATA[in-order-traversal]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[tree-data-structures]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Tue, 16 Nov 2021 09:05:00 GMT</pubDate>
            <atom:updated>2021-11-16T09:05:00.234Z</atom:updated>
            <content:encoded><![CDATA[<p>In last post<a href="https://paragnaik2019.medium.com/introduction-to-tree-data-structures-31c7976979a5"> Introduction to tree data structures</a>, I have give a brief introduction about tree data structure and its applications. Traversing a tree data structure is interesting as well as complicated as compare to linear data structures. Unlike arrays or linked list which are traversed in linear order, tree data structure can we traversed in multiple ways like <strong>depth first order</strong> (inorder, preorder, postorder) and <strong>breadth first order</strong>(level order traversal).In this article we will discuss inorder traversal using two approaches the iterative way and recursive way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lmpPkdhKBGC3z1_l" /><figcaption>left node or right node</figcaption></figure><p>Each node of the tress needs to be visited in some specific way while traversing a tree. Unlike linear data structure , there can be more than one possible next node from a given root node because of the some nodes must be skipped i.e. stored in some way so that it can be visited later. The traversing can be done iteratively where the stored skipped node is stored in a stack or it can also be done by recursion, where the skipped node is stored implicitly in a call stack.</p><p>While traversing a non-empty binary tree in an inorder way, three things need to be done for every <strong>“n”</strong> node starting from the tree root.<br>1. Traverse the left subtree and print the node value. when this step is finished return back to <strong>“n” node.<br></strong>2. Print the <strong>“n”</strong> node value<br>3. Traverse the right subtree and print the node value. when this step is finished return back to <strong>“n”</strong> node</p><p>Let us first discuss the iterative approach along with the code.<br><strong>1</strong>. <strong>Iterative method-<br></strong>The left subtree needs to processed first before processing any other node followed by the root node and at last the right node or right subtree. In the iterative approach we will use an explicit stack to perform inorder traversal. Below is the code:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0eb1de780ceb426c2dbb80be4664e557/href">https://medium.com/media/0eb1de780ceb426c2dbb80be4664e557/href</a></iframe><p>We will create a empty stack to hold the skipped node. We will start from the root and set the current node to root node. If the current node is none and stack is empty ,we will exit the while loop. Inside the while loop we will check if the current node is present , we will push the current node to the stack and we will skip the current node and move to the left node. After moving to the left node if the current node is none , we will pop the node from the stack and place it in current node. We will append the current node value in the list inorder and then move to the right node of the current. At last we will return the inorder list which holds all the traversed value of the tree</p><p>2. <strong>Recursive method-<br></strong> Similar to the iterative approach we will first visit the left subtree then the root node and at last the right subtree. This operation are done recursively on each node</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3081fd62b8a772f7f58e60a531a0a1a/href">https://medium.com/media/a3081fd62b8a772f7f58e60a531a0a1a/href</a></iframe><p>We will star from the root node, if the root node is empty we will return a empty list. Similar to iterative approach we will first visit the left subtree , recursion will place the skipped node in implicitly in a call stack . It will append the left node values in element list and then return back to the root node , the root node value is stored in the element list. Once the left node value becomes none , we will move to right node and perform the same operation and place the values of right node in element list. At last we will return the element list which hold all the traversed values of the tree.</p><p><strong>Time and space complexities-<br></strong>The time complexity of the above code is O(n),where n is total number of node in a binary tree. The space complexity of the code is O(n) as space required a directly proportional to the height of the tree which in case can be equal to the total number of nodes in the trees in worst case for skewed trees.</p><p><strong>Conclusion-<br></strong>Traversing in simple words means exploring, we all are in journey of life. But this journey is not about the end its about experiences and challenges. My only message to readers is enjoy the journey ,keep learning and never ever give up. At the end everything works out for the best…..(cheers-PN)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70250862d5b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Tree data structures]]></title>
            <link>https://paragnaik2019.medium.com/introduction-to-tree-data-structures-31c7976979a5?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/31c7976979a5</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[trees]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Fri, 05 Nov 2021 07:11:34 GMT</pubDate>
            <atom:updated>2021-11-05T07:11:34.322Z</atom:updated>
            <content:encoded><![CDATA[<p>In the realm of data structures, Linked list, array can be described as a linear data structure unlike trees which are non-linear, hierarchical data structures.</p><p>A tree can be defined as a collection of nodes in which node stores a value and a list referencing to children nodes. Best real life example of tress is folder structure in our computers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*WbS0CskZ_tNbMVcNuXKBCA.png" /><figcaption>Tree</figcaption></figure><p>What is a Binary tree?<br>A binary tree can be described as a data structure consisting of a node where each node has up to two child nodes that create a branches of tree. This two children are called left node and right node. Child node always contains a reference to parent node. The top most node of the tree is called the root node, the node which is left of the root node is called left node which serves as the root for the left sub tree, whereas the one to the right is called the right node which also serves as the root node for the right sub-tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-rl3hS-QAOZ6zTKO" /><figcaption>Save tree</figcaption></figure><p>Types of binary trees:-<br>1. <strong>Full Binary Tree</strong>-A binary tree which has either 0 nodes or 2 nodes is called a full binary tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*oYANQ2DdwaRPLbH-SSuWug.png" /><figcaption>Full Binary Tree</figcaption></figure><p>2. <strong>Complete Binary tree</strong>-A binary tree in which all the levels are completely filled except the last level and the last level should have all the nodes left as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*yoDOLXrJ_Sn-IOkmd1p9cA.png" /><figcaption>Complete Binary Tree</figcaption></figure><p>3. <strong>Perfect Binary tree</strong>-In a perfect binary tree, all the leaf nodes are at same level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*KpVff6Bd8_xxmqakF27xfA.png" /><figcaption>Perfect Binary tree</figcaption></figure><p>4. <strong>Balance binary tree</strong>- If the height of the binary tree is O(Log n), where n is number of node such tree is a balance binary tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*rcNHMXrlsqEtdX97chzdJA.png" /><figcaption>Balance binary tree</figcaption></figure><p>5. <strong>Degenerated tree</strong>-A degenerated tree is a tree where all the internal node has one child , such tree act like a linked list in terms of performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*h2HiABwh4OQf3OLu26bZYg.png" /><figcaption>Degenerated tree</figcaption></figure><p><strong>Conclusion</strong>:-<br>Tree data structure have many real world examples like compression algorithms, wireless networks and memory allocation. It is time to rise from ashes. cheers-PN</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31c7976979a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leetcode-206 :-Reverse Linked List]]></title>
            <link>https://paragnaik2019.medium.com/leetcode-206-reverse-linked-list-30ce4fa2b09?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/30ce4fa2b09</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Fri, 14 May 2021 12:37:43 GMT</pubDate>
            <atom:updated>2021-05-14T12:37:43.422Z</atom:updated>
            <content:encoded><![CDATA[<h3>Leetcode-206 :-Reverse Linked List</h3><p>Given the head of a singly linked list, reverse the list, and return <em>the reversed list</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*cxEdYLBh8Oa-lQIzrCFaeg.png" /><figcaption>Image of reversed linked list.</figcaption></figure><p>A easy category linked list problem where we need to reverse the Linked list.For this there are two method-iterative and recurrssive method.Here we will apply the iterative method. For this method we will need to use to variable “prev” and “next_current”.Let’s move toward the code.</p><pre>def reverseList(self, head: ListNode) -&gt; ListNode:<br>    prev=None<br>    current=head<br>    while current:<br>        next_current=current.next<br>        current.next=prev<br>        prev=current<br>        current=next_current<br>    current=head<br>    return prev</pre><p>First we will give initial value of Null to prev variable and save head of Linked list in variable “current”. The we will iterate the Linked list using a while loop.we will put the next value of current i.e head in the variable next_current and point the next of current to prev variable as it holds the null value.The change the value of prev to current and move current to next_current as it hold the link to next element in Linked List and once the loop exit the last element will be made head and we will return prev which holds the reverse list.</p><p>Conclusion:-<br><strong>“Difficult things aren’t easy but they are worth it”.<br></strong>Interesting quote and it fits well for Data structure which always seems difficult but once learning start it ain’t that difficult. Move out of Comfort zone.Keep learning and Keep hustling…(cheers:PN)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30ce4fa2b09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “Hello world” of Data Structure-Linked List.]]></title>
            <link>https://paragnaik2019.medium.com/the-hello-world-of-data-structure-linked-list-159bba7e4044?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/159bba7e4044</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Wed, 12 May 2021 12:07:40 GMT</pubDate>
            <atom:updated>2021-05-12T12:07:40.149Z</atom:updated>
            <content:encoded><![CDATA[<p>Linked is type of linear data structure which is widely use to solve specific problem raise due to the limitation of arrays.<br>Linked list can be define as linear data structure in which the elements are not stored in contiguous memory location. In Laymen terms we can say a linked list is a collection of nodes in which each node has a data and the reference to the next node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*Z9z7gTrNtxxzcm1lp_2WEw.png" /><figcaption>Diagram of a Linked List.</figcaption></figure><p>The first node of the linked list is called as Head and the last node of the linked list points to null. In this tutorial we will perfomer following operations:-<br>1.Insert at the start of Linked List.<br>2.Insert at the end of the Linked List.<br>3.Insert at a specific index /position in the Linked List.<br> I have implemented the above operation on linked list in python and using OOPs approach.</p><p>In python we have use two different class to represent node and head of the Linked List.</p><pre>class Node:<br>    # Function to initialize the node object<br>    def __init__(self,data=None,next=None):<br>        self.data=data   #Assign data <br>        self.next=next   #Initialize next to Null<br>    <br>class Linkedlist:<br>    # Function to initialize the Linked list object<br>    def __init__(self):<br>        self.head=None</pre><ol><li><strong>Insert element at the Start of the Linked List:-</strong><br>Inserting an element in linked list at start is comparatively easy.Here we have to create a node and make it as the head of the linked list and point the reference link of this node to next reference link of the head.Below is the code for it.</li></ol><pre>def insert_at_begining(self,data):<br>    node=Node(data,self.head)<br>    self.head=node</pre><p>Here we will first create a node and pass data to it and reference link to this node will be that of head. Then we will this node as head.</p><p>2. Insert element at the end of Linked List:-<br>To insert the element at the end of the linked list we will have traverse the entire Linked-list.First we will have to check if the linked list is element or not ,for that we will check if the head is present or not.If not we will create a node and make it as head.If the head is present in Linked list,we will create a temperory variable say “itr” and give head as its value.Then we will iterate the entire list till we reach the end thats when the while loop will exit and then we will create a node with the next reference value as null.</p><pre>def insert_at_end(self,data):<br>    if self.head is None:<br>        print(&quot;Linkedlist is empty&quot;)<br>        node=Node(data,self.head)<br>        self.head=node<br>    itr=self.head<br>    while itr.next:<br>        itr=itr.next<br>    itr.next=Node(data,None)</pre><p><strong>3.Insert at a specific index /position in the Linked List-<br></strong>In this operation we have insert a node at a specific position of the Linked List.<br>a. first we will check if the given index is valid or not i.e it is in the range of length of linked list ,if not we will then raise an exception saying “Invalid Linked List”.<br>b. If the given position is index=0,then we will create a node and make it as head, pretty simple.<br>c. Now the tricky part of insert at other positions,first we will create a temperory variable “itr” which will hold the head of the linked list and a counter variable initialized to 0.Then we will iterate the entire linked list and check if we have reached at the previous node of given index.if so we will then create a node and point the reference link of the new node to the reference link of the previous node and point the previous node to the new node.If we are not the require index we will keep on iterating the linked list and also the counter.</p><pre>def insert_at(self,index,data):<br>    if index&lt;0 or index&gt;=self.get_length():<br>        raise Exception(&quot;Invalide index given&quot;)<br>        <br>    if index==0:<br>        node=Node(data,self.head)<br>        self.head=node<br>        print(&quot;data inserted at begining&quot;)<br>    <br>    itr=self.head<br>    count=0<br>    while itr.next:<br>        if count==index-1:<br>            node=Node(data,itr.next)<br>            itr.next=node<br>        itr=itr.next<br>        count+=1<br>        <br>    return &quot;Node inserted&quot;</pre><p>Conclusion:-<br>Po from Kung-fu panda has taught we a lot and will keep on teaching me, that no matter how bad thing came/happened in past there is not point in holding onto it because it does not matter, its just either you can learn from it or run from it.I choose to learn from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*X_mY-CJJXnXVoOP40FXnJg.png" /></figure><p>Keep learning and keep hustling…(cheers:-<strong><em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=159bba7e4044" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beautiful Triplets]]></title>
            <link>https://paragnaik2019.medium.com/beautiful-triplets-ce91af89d067?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce91af89d067</guid>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 11:13:22 GMT</pubDate>
            <atom:updated>2021-04-20T11:13:22.372Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem statement:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*VDxEEBkAdMut80vR57lsjg.png" /><figcaption>Problem statement with example</figcaption></figure><p>Solution:-<br>A very straight forward hackerrank problem where we have to find the count of triplet form based on condition given in the problem statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ZOkF_oorn6qstoF" /><figcaption>Photo by <a href="https://unsplash.com/@maskresna?utm_source=medium&amp;utm_medium=referral">rahmani KRESNA</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In one of the approach we could use 3 for loops but it will create problem for huge array and thus hamper the execution time and degrade the time complexity. Let’s move towards the code.</p><pre>def beautifulTriplets(d, arr):<br>    count=0<br>    for i in range(len(arr)):<br>        j=arr[i]+d<br>        if j in arr and j+d in arr:<br>            count+=1<br>    return count</pre><p>We will first declare a variable which will count the number of triplets say count and initialize it to 0.The we will iterate each element in the list and add “d” to it and store it in “j” and check if the sum is present in the list if so the first condition i.e arr[i]-arr[j]=d and then we will d to j to check for condition arr[k]-arr[j]=d.If both the conditions are staified we will increment count by one and at the end of the iteration we will return the value of count.</p><p>Conclusion:-<br>“<strong>Life is about how much you can take and keep fighting, how much you can suffer and keep moving forward</strong>.”<br>Currently I am in a lockdown and each day is very tough for me.Things are not working for me,feels like I am stuck .This is the best quote I could hang on to it.Keep learning and keep hustling…(cheers:-<strong><em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce91af89d067" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Halloween Sale]]></title>
            <link>https://paragnaik2019.medium.com/halloween-sale-95d717636336?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/95d717636336</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Sat, 10 Apr 2021 07:11:07 GMT</pubDate>
            <atom:updated>2021-04-10T07:11:07.925Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Problem:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*W6fk-DFhR9DXf2sQ2kMYkQ.png" /><figcaption><strong>Problem statement</strong></figcaption></figure><p><strong>Solution:-<br>A</strong> straight forward hackerrank problem where we have to calculate the number of gifts one can buy with given amount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AUBGlDcxODuW-J_G" /><figcaption>Photo by <a href="https://unsplash.com/@bekirdonmeez?utm_source=medium&amp;utm_medium=referral">Bekir Dönmez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Lets move toward the code,we will have to declare two variables n and count with intially value n=p and count =0.</p><pre>def howManyGames(p, d, m, s):<br>    n=p<br>    count=0<br>    while n&lt;=s:<br>        p=p-d<br>        if p&lt;=m:<br>            n+=m<br>            count+=1<br>        else:<br>            n+=p<br>            count+=1<br>    return count</pre><p>We will use a while loop which will run a long as the value of n is less than or equal to s. ”n” will hold the cost of each gift after the discount has been deducted.After purchasing the first gift without any discount ,we will deduct d from p and store it again in p. Then we will check whether the value of p is less than or equal to m,as per the condition give if this condition is statisfy we will add m to n and increment the counter by.In the else-part we will add p to n and increment the counter by 1.As the loop runs out we will return count which will hold the number of gifts we have purchased in the given pocket money.</p><p>Conclusion:-<br><strong>“ If you learn self-control, you can master anything.”</strong> <br>quote which sums up todays time where exercising self control has become so difficult.Keep learning and Keep hustling…(Cheers:-<strong><em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95d717636336" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Minimum Distances]]></title>
            <link>https://paragnaik2019.medium.com/minimum-distances-fda7a03b7d97?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fda7a03b7d97</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Wed, 07 Apr 2021 11:23:06 GMT</pubDate>
            <atom:updated>2021-04-07T11:23:06.467Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem:-The distance between two array values is the number of indices between them. Given a, find the minimum distance between any pair of equal elements in the array. If no such value exists, return -1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*TIJKaR5lSVSNq_BAl1uj3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X574ygKCNutJCE2Y" /><figcaption>Photo by <a href="https://unsplash.com/@marekpiwnicki?utm_source=medium&amp;utm_medium=referral">Marek Piwnicki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Solution:-<br>A very straight forward and easy hackerrank problem, in which we have to find the distance between multiple matching pair and return the minimum among them. Lets move towards the code.</p><pre>def minimumDistances(a):<br>    lst=[]<br>    for i in range(len(a)):<br>        for j in range(i+1,len(a)):<br>            if a[i]==a[j]:<br>                lst.append(j-i)<br>    if len(lst)==0:<br>        return -1<br>    else:<br>        return min(lst)</pre><p>Here we will first declare an empty list in which we will insert the distance between two matching pair. We will use two for loop ,the first for loop we run till the end of the list “a” and second will start at i+1.we will check if the element has a matching pair inside the list ,if so we will find the distance between them (index) and then append it in the list lst.Then in the next if condition we will find the minimum among the distance inserted in the list lst.if no matching pair is found we will return -1.</p><p>Conclusion:-<br><strong>“If God closes a door and a window, consider the fact that it might be time to build a whole new house”</strong>. I have seen multiple doors and windows shot down in my life hope this door is a way to my new world. Keep working and keep hustling….(Cheer:-<strong><em>PN</em></strong>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fda7a03b7d97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Repeated String]]></title>
            <link>https://paragnaik2019.medium.com/repeated-string-9a6355c84b6a?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a6355c84b6a</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 14:33:46 GMT</pubDate>
            <atom:updated>2021-04-06T14:33:46.216Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem Statement:-<br>There is a string ”s”, of lowercase English letters that is repeated infinitely many times. Given an integer ,”n”. Find and print the number of letter “a” in string “s” in the first “ n” letters of the infinite string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qtyKv-mtGSjUahks" /><figcaption>Photo by <a href="https://unsplash.com/@crawford?utm_source=medium&amp;utm_medium=referral">Crawford Jolly</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Solution:-<br>Interesting hackerrank problem where we need to find the letter “a” in first “n“ letters a given string which is repeated infinitely. Lets move towards the code.In the first if-condition we will consider an edge case where the string has only single letter which is “a”,as it is a single letter and it’s “a” it will repeat exactly “n” number of times.</p><pre>def repeatedString(s, n):<br>    if len(s)==1 and s==&quot;a&quot;:<br>        return n<br>    else:<br>        b=s.count(&quot;a&quot;)<br>        x=n//len(s)<br>        z=b*x<br>        remaining=n-(x*len(s))<br>        y=s[:remaining].count(&quot;a&quot;)<br>        return z+y</pre><p>The else-condition is where the entire problem lies,first we will count the number of “a” in the given string and store the count in variable “b”.The we will calculate the minimum times the string will be repeated for first “n” number of variable by dividing “n” with the length of the string and store it in “x”. Then we will multiply the number of “a”s in string with x and store it in “z”.Now we will find the remaining part which is nothing but the difference between “n” and product of “x” and the length of “s”. Then we will count the number of “a” in the remaining part and store it in y. In next line we will return the sum of z and y.</p><p>Conclusion:-<br>“<strong>All you need in this life is ignorance and confidence, and then success is sure</strong>”. As per the famous quote all we need to ignore the negativity in our surround and keep on moving and hustling….(<strong>Cheers:-<em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a6355c84b6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Taum and B’day]]></title>
            <link>https://paragnaik2019.medium.com/taum-and-bday-dd3565514722?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd3565514722</guid>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 11:31:07 GMT</pubDate>
            <atom:updated>2021-03-31T11:31:07.499Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem Statement:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*08ocKsYw_CH_jjw9LpnGQA.png" /></figure><p>Solution:-<br>A very simple one line solution to this problem. Here we are trying to find out the minimum cost at which we can buy both white and black gifts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o0mMuxtysfD0Uijl" /><figcaption>Photo by <a href="https://unsplash.com/@adigold1?utm_source=medium&amp;utm_medium=referral">Adi Goldstein</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If the cost of black gift is less than that of white gift we will convert the white gift into black along with a conversion factor added to the cost of black gifts and vice versa is also possible.Lets move towards the code.</p><pre>def taumBday(b, w, bc, wc, z):<br>    return min(b*bc+w*wc, b*(wc+z)+w*wc, b*bc+w*(bc+z))</pre><p>This is a one-line problem statement where we find(return) the minimum value among the total cost without any conversion, total cost when we have converted the black gift into white and the total cost when we have converted the white gift into black.</p><p><strong>Conclusion:-</strong><br>“<em>Do today what others won’t so tomorrow you can do what others can’t.” <br></em>I have been away from this challenge but I have picked it up again from today.<br>Keep moving and keep hustling….(cheers:-<strong><em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd3565514722" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jumping on the Clouds]]></title>
            <link>https://paragnaik2019.medium.com/jumping-on-the-clouds-d9c54979e5c2?source=rss-198f075d206c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9c54979e5c2</guid>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Parag Naik]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 11:23:00 GMT</pubDate>
            <atom:updated>2021-03-22T11:23:00.400Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Problem statement:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*Clwt1jk_DKAmXN_8UP_wcg.png" /></figure><p>Solution:-Simple but not so straight forward hackerrank problem where we have to count the number of jumps based on which type of cloud is allowed to jump on it or not in that case the jump range will increase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C-L6ER94s0IWm7FE" /><figcaption>Photo by <a href="https://unsplash.com/@jeisblack?utm_source=medium&amp;utm_medium=referral">Jason Blackeye</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let move towards the code,we declare two variables “i” and “jump” and give them an initial value of 0.We will iterate the cloud list using a while loop which iterate till (length of cloud list-1) as we need to iterate each and every cloud type in cloud list.We will compare the i+1 and i+2 cloud in the list for current iteration and based on that we will jump by 2 jumps or 1 jump.</p><pre>def jumpingOnClouds(c):<br>    jump,i=0,0<br>    while i&lt; n-1:<br>        if i+2&lt; n and c[i+2]==0:<br>            i+=2<br>            jump+=1<br>        elif i+1&lt; n and c[i+1]==0:<br>            i+=1<br>            jump+=1<br>    return jump</pre><p>along with that in if loop we will always check if the cloud list has not been exhausted i.e i+2&lt;n or i+1&lt;n. We will increment the number of jumps and value of i in each iteration based on jump count.</p><p><strong>Conclusion:-<br>“Try and Fail but don’t Fail to Try”.<br></strong>An excellent quote for this problem as I have been struggling to optimize my solution for this problem. Keep learning and Keep hustling…(cheers:-<strong><em>PN</em></strong>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9c54979e5c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>