<?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[THEBUG - Medium]]></title>
        <description><![CDATA[Learn to code, the weird way! - Medium]]></description>
        <link>https://medium.com/thebug?source=rss----8cbf93597b---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>THEBUG - Medium</title>
            <link>https://medium.com/thebug?source=rss----8cbf93597b---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:23:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/thebug" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Product of Array Except Self]]></title>
            <link>https://medium.com/thebug/product-of-array-except-self-788b30d2e981?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/788b30d2e981</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Tue, 15 Mar 2022 21:56:59 GMT</pubDate>
            <atom:updated>2022-03-15T21:56:59.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7yRJRGEpbN1218ZodyCWUg.png" /></figure><p>Another popular algorithm interview question, this question is the same as — Leetcode 238. Product of Array Except Self</p><p>The problem description usually says: <strong><em>For an integer array, return an answer where answer[i] is equal to the product of every other element except array[i] without using division.</em></strong></p><p>So, something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vq2xTDPiNCoBtTncu6eFQw.png" /></figure><p>ans[0] = array[1]*array[2]*array[3]</p><p>ans[1] = array[0]*array[2]*array[3]</p><p>ans[2] = array[0]*array[1]*array[3]</p><p>ans[3] = array[0]*array[1]*array[2]</p><h3><strong>Solution</strong></h3><h4>Brute Force O(n²)</h4><p>The brute force answer for this would use two nested loops and calculate the answer and would look something like —</p><pre>array = [1,2,3,4]<br>answer = []<br>for i in range(len(array)):<br>    totalProduct = 1</pre><pre>    for j in range(len(array))<br>        if i != j: totalProduct*=array[j]<br>    answer.append(totalProduct)<br>return answer</pre><p>We go through every combination of elements and multiply it, skipping the current element and adding to our answer array. In the end we can simply return the answer.</p><p>Our loops are running for n*n times making this a<strong> O(n²)</strong> solution, and we can do better than this —</p><h4>Optimal O(n)</h4><p>If you look hard enough — what we need to do is pretty simple — to find the answer[2] we need to multiply everything before and after answer[2] like explained above —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dE9nusCwe_bUIz36wBJdMw.png" /></figure><p>So what if we do that and store it, if we create two arrays, one being a product array of all the elements to the left and one being a product array of all the elements to the right —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwON36g-XsgnTY7CIXHImQ.png" /></figure><p>At any “i” in the right product array shown above has the product of everything to its right, and similarly, any “i” in the left product array shown above has the product of everything to its left —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WPjaf-oxuWXeB67dqhyhRw.png" /><figcaption>Right Prod Array</figcaption></figure><p>So now for any array[i] —</p><p>the answer[i] will be — <strong>leftProd[i-1]*rightProd[i+1]</strong></p><p>This is how we calculate the answer array optimally —</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252873%252C145%252C255%252C1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dapplication%252Fx-sh%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D32px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D100px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D13px%26lh%3D133%2525%26si%3Dfalse%26es%3D4x%26wm%3Dfalse%26code%3Dclass%252520Solution%25253A%25250A%252520%252520%252520%252520def%252520productExceptSelf%2528self%25252C%252520nums%25253A%252520List%25255Bint%25255D%2529%252520-%25253E%252520List%25255Bint%25255D%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520rightMul%25252C%252520leftMul%252520%25253D%2525201%25252C%2525201%25250A%252520%252520%252520%252520%252520%252520%252520%252520answer%252520%25253D%252520%25255B%25255D%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520i%252520in%252520range%2528len%2528nums%2529%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520leftMul%252A%25253Dnums%25255Bi%25255D%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520answer.append%2528leftMul%2529%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520i%252520in%252520range%2528len%2528nums%2529-1%25252C-1%25252C-1%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520if%252520i%25253E0%25253A%252520answer%25255Bi%25255D%252520%25253D%252520answer%25255Bi-1%25255D%252ArightMul%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520else%25253A%252520answer%25255Bi%25255D%252520%25253D%252520rightMul%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520rightMul%252A%25253Dnums%25255Bi%25255D%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520return%252520answer%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252873%25252C145%25252C255%25252C1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dapplication%25252Fx-sh%26width%3D680%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D32px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D100px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D13px%26lh%3D133%252525%26si%3Dfalse%26es%3D4x%26wm%3Dfalse%26code%3Dclass%25252520Solution%2525253A%2525250A%25252520%25252520%25252520%25252520def%25252520productExceptSelf%252528self%2525252C%25252520nums%2525253A%25252520List%2525255Bint%2525255D%252529%25252520-%2525253E%25252520List%2525255Bint%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520rightMul%2525252C%25252520leftMul%25252520%2525253D%252525201%2525252C%252525201%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520answer%25252520%2525253D%25252520%2525255B%2525255D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520i%25252520in%25252520range%252528len%252528nums%252529%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520leftMul%25252A%2525253Dnums%2525255Bi%2525255D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520answer.append%252528leftMul%252529%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520i%25252520in%25252520range%252528len%252528nums%252529-1%2525252C-1%2525252C-1%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520i%2525253E0%2525253A%25252520answer%2525255Bi%2525255D%25252520%2525253D%25252520answer%2525255Bi-1%2525255D%25252ArightMul%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520else%2525253A%25252520answer%2525255Bi%2525255D%25252520%2525253D%25252520rightMul%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520rightMul%25252A%2525253Dnums%2525255Bi%2525255D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520answer%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e596171f279efc100ddcea4bcd2287e/href">https://medium.com/media/8e596171f279efc100ddcea4bcd2287e/href</a></iframe><p>In the solution above, instead of using two arrays, one of left prod and one for right prod, only one array is being using, we are keeping track of one of the arrays on the fly using the rightMul variable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=788b30d2e981" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/product-of-array-except-self-788b30d2e981">Product of Array Except Self</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Sum Using Python]]></title>
            <link>https://medium.com/thebug/two-sum-using-python-e2b2a46addc3?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/e2b2a46addc3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 01:50:02 GMT</pubDate>
            <atom:updated>2022-01-06T00:53:15.223Z</atom:updated>
            <content:encoded><![CDATA[<h3>Two Sum</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shsCWXyupV54CVlTZ7-ucg.jpeg" /></figure><p>Today we discuss the infamous interview question — Two Sum - If you are prepping for an technical interview or just grinding leetcode or hackerrank or just trying to kill time casually browsing trough a CS book, you probably have stumbled upon this quesiton.</p><p>It usually is phrased something like —</p><p>Given an array of numbers and an target value, find out where the sum of the two numbers exist within the array.</p><p>At first glance, the question seems pretty easy, just go through the array and find out the two numbers. Right? Well, yes and no, if you are trying to crack a technical interview this answer might not get you the results you are trying to get. There is a much more efficient way of doing it within O(n) time. And that is what we will discuss in this article.</p><p>The logic behind this O(n) approach is that if you substract the target from an element from the array, the result is also within the array, you have your answer. Lets use an example —</p><p>[1,2,3,4,5] — Lets say we have this array, and the target we are trying to find is 6. We can see that 2 and 4 within the array and they add up to a 6. Using this logic, if we take the target — 6 and subtract it with 2, it leaves us with 4, and we know (using the dictionary) that 4 is at the 3rd index of the array.</p><p>First we define the dictionary, and populate it with the index number of each of the elements—</p><pre>dictionary = {}<br>for i in range(len(nums)):<br>    dictionary[nums[i]] = i</pre><p>Then we once again iterate over the list/array, subtract each number with the target and use .get() to see if the result of the subtraction exists within the dicitonary. Also, we need to make sure we arent using the same element twice to create the result — For instance, in case of this array — [1,2,3,4,5], you can use 3 twice to make a 6, but that is not what we want to do here, which is why we use the dictionary to check if the index of the subtraction result not the same as the index we are on using —</p><pre>i!=dictionary[target-nums[i]]</pre><p>And here is the full code —Enjoy!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252874%252C144%252C226%252C1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%252520twoSum%2528self%25252C%252520nums%25253A%252520List%25255Bint%25255D%25252C%252520target%25253A%252520int%2529%252520-%25253E%252520List%25255Bint%25255D%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520dictionary%252520%25253D%252520%25257B%25257D%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520i%252520in%252520range%2528len%2528nums%2529%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520dictionary%25255Bnums%25255Bi%25255D%25255D%252520%25253D%252520i%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520for%252520i%252520in%252520range%2528len%2528nums%2529%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520if%252520dictionary.get%2528target%252520-%252520nums%25255Bi%25255D%2529%252520and%252520i%2521%25253Ddictionary%25255Btarget-nums%25255Bi%25255D%25255D%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520return%252520%25255Bi%25252Cdictionary%25255Btarget-nums%25255Bi%25255D%25255D%25255D%25250A%252520%252520%252520%252520%252520%252520%252520%252520&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252874%25252C144%25252C226%25252C1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%25252520twoSum%252528self%2525252C%25252520nums%2525253A%25252520List%2525255Bint%2525255D%2525252C%25252520target%2525253A%25252520int%252529%25252520-%2525253E%25252520List%2525255Bint%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520dictionary%25252520%2525253D%25252520%2525257B%2525257D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520i%25252520in%25252520range%252528len%252528nums%252529%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520dictionary%2525255Bnums%2525255Bi%2525255D%2525255D%25252520%2525253D%25252520i%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520for%25252520i%25252520in%25252520range%252528len%252528nums%252529%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520dictionary.get%252528target%25252520-%25252520nums%2525255Bi%2525255D%252529%25252520and%25252520i%252521%2525253Ddictionary%2525255Btarget-nums%2525255Bi%2525255D%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520%2525255Bi%2525252Cdictionary%2525255Btarget-nums%2525255Bi%2525255D%2525255D%2525255D%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e0e84d6133974bd017f8d06c2afca8c/href">https://medium.com/media/6e0e84d6133974bd017f8d06c2afca8c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2b2a46addc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/two-sum-using-python-e2b2a46addc3">Two Sum Using Python</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search]]></title>
            <link>https://medium.com/thebug/binary-search-3edfba7040f1?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/3edfba7040f1</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 15:16:40 GMT</pubDate>
            <atom:updated>2022-01-05T22:19:05.617Z</atom:updated>
            <content:encoded><![CDATA[<h3>Binary Search Using Python</h3><p><em>Note that there are two ways to perform binary search — iterative and recursive, we will only discuss the iterative way to perform binary serach.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQ_g58PIS4m3UGGqr_Gw5Q.jpeg" /></figure><p>Binary Search is a commonly used algorithm to search a sorted list and with its O(log n) worse case complexity, its a thousand times faster than linear search. It is also one of the most commonly used algorithm questions during tech interviews.</p><p>Lets discuss how to implement Binary Search —</p><p>Lets take a sample array — [1,2,3,4,5,6] and try to figure out if the number 5 is within this sorted list using python.</p><p>The way Binary Search works is it takes a look at the middle element and sees if it is either bigger or smaller than the number we are trying to find —</p><p>If the number in the middle is the number we are trying to find, viola! we have found the value, and we don’t need to do anything else, however if the middle is bigger than the number we are trying to find, we know that the number is on the right side of the list.</p><p>[1,2,3,4,5,6] — middle is 4. (We are looking for 5, since the numbers on the right are bigger 5 must be in there)</p><p>Likewise, if the middle is smaller we know that the number we are looking for is on the left.</p><h3><strong>The Code</strong></h3><p>Now that we have discussed the theory of how Binary Search works, lets get into the code.</p><p>Remember, everything depends on the mid, so one of the most iportant things we need to do is, find the mid. And mid is simply the mid of the list. To calcualte this we need to just find the first — index, the last index and divide it by 2 — mid = (start + end)//2. (// is the floor division operator in python)</p><p>But wait! What is the start and the end? Initially the start will be 0 and the end will be the end of the list (len(list)-1), as we go about searching for our target element, we update the start and the end accordingly.</p><p>Here is the full solution —</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%252874%252C144%252C226%252C1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%252520search%2528self%25252C%252520nums%25253A%252520List%25255Bint%25255D%25252C%252520target%25253A%252520int%2529%252520-%25253E%252520int%25253A%25250A%252520%252520%252520%252520start%252520%25253D%2525200%252520%25250A%252520%252520%252520%252520end%252520%25253D%252520len%2528nums%2529-1%25250A%252520%252520%252520%252520while%252520%2528start%252520%25253C%25253D%252520end%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520mid%252520%25253D%252520%2528%2528start%25252Bend%2529%25252F%25252F2%2529%25250A%252520%252520%252520%252520%252520%252520%252520%252520if%252520%2528nums%25255Bmid%25255D%25253D%25253Dtarget%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520return%252520mid%25250A%252520%252520%252520%252520%252520%252520%252520%252520elif%252520%2528nums%25255Bmid%25255D%25253Ctarget%2529%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520start%252520%25253D%252520mid%25252B1%25250A%252520%252520%252520%252520%252520%252520%252520%252520else%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520end%252520%25253D%252520mid-1%25250A%252520%252520%252520%252520return%252520-1%25250A%252520%252520%252520%252520%252520%252520%252520%252520&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%25252874%25252C144%25252C226%25252C1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2BCode%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Ddef%25252520search%252528self%2525252C%25252520nums%2525253A%25252520List%2525255Bint%2525255D%2525252C%25252520target%2525253A%25252520int%252529%25252520-%2525253E%25252520int%2525253A%2525250A%25252520%25252520%25252520%25252520start%25252520%2525253D%252525200%25252520%2525250A%25252520%25252520%25252520%25252520end%25252520%2525253D%25252520len%252528nums%252529-1%2525250A%25252520%25252520%25252520%25252520while%25252520%252528start%25252520%2525253C%2525253D%25252520end%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520mid%25252520%2525253D%25252520%252528%252528start%2525252Bend%252529%2525252F%2525252F2%252529%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520if%25252520%252528nums%2525255Bmid%2525255D%2525253D%2525253Dtarget%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520return%25252520mid%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520elif%25252520%252528nums%2525255Bmid%2525255D%2525253Ctarget%252529%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520start%25252520%2525253D%25252520mid%2525252B1%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520else%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520end%25252520%2525253D%25252520mid-1%2525250A%25252520%25252520%25252520%25252520return%25252520-1%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/add5cbf484c9571cfb5b8648b9d7e1bc/href">https://medium.com/media/add5cbf484c9571cfb5b8648b9d7e1bc/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3edfba7040f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/binary-search-3edfba7040f1">Binary Search</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Insertion Sort using Python]]></title>
            <link>https://medium.com/thebug/insertion-sort-using-python-b58e38e5998f?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/b58e38e5998f</guid>
            <category><![CDATA[insertion-sort]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Sun, 14 Oct 2018 18:16:14 GMT</pubDate>
            <atom:updated>2018-10-14T18:16:13.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7YglXbPfM9ePGdUf83_tNg.jpeg" /></figure><p>Insertion sort is a pretty straightforward sorting algorithm. Even though it’s not efficient it serves as a good starting point for people who are just starting to learn sorting algorithms.</p><p>In insertion sort, we choose a key and then traverse the array backward to find its right place.</p><h3>The Algorithm</h3><pre>[3,20,5,7,1]</pre><p>Let us start with 3. We compare 3 with 3 they are the same so we do not need to do anything. We</p><p>We then move on to 20 we check if its smaller than 3 if it is then we swap the places if it&#39;s not then we don&#39;t. 20 is clearly not smaller than 3 so we don&#39;t do anything.</p><p>We then move on to number 5. We go backward to 20 and check if it is smaller than 20, which it indeed is. Now we swap.</p><pre>[3,5,20,7,1]</pre><p>We then check if 5 is smaller than 3. It is not so we do not do anything.</p><p>Now the key is number 7, we check if 7 is less than 20 and we swap. The array looks something like this.</p><pre>[3,5,7,20,1]</pre><p>Similarly, for one we do the same, and since it is the smallest number in the array. We will keep swapping and the array will now be sorted.</p><pre>[1,3,5,7,20]</pre><h3>The Code</h3><p>We use two loops to do this. One to traverse the whole array while one to go backward in the array. We check and then we swap and then we repeat the process again.</p><pre>def insertion(arr): //Defining the function.<br>    for i in range(0,len(arr)): //First loop to go over all elements<br>        elem=arr[i]<br>        for j in range(i,-1,-1)://Loop to go back and compare.<br>            if arr[j]&gt;=arr[i]: //Comparing.<br>                temp=arr[i] //Swapping.<br>                arr[i]=arr[j]<br>                arr[j]=temp<br>                i=j<br>    return(arr) //Returning the sorted array.<br>            <br>insertion([1,5,2,20,9,29,3,0])</pre><p>Congratulations! Now you have a basic understanding of how insertion sort works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b58e38e5998f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/insertion-sort-using-python-b58e38e5998f">Insertion Sort using Python</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[In Order Traversal Using Stacks (Python)]]></title>
            <link>https://medium.com/thebug/in-order-traversal-using-stacks-python-4207d87dd33e?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/4207d87dd33e</guid>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[inorder-traversal]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 14:49:33 GMT</pubDate>
            <atom:updated>2018-07-24T14:49:32.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AO6a6Biz8IqZ9p2DUqi_UA.jpeg" /></figure><p>Trees are one of the relatively complicated data structure that you will have to tackle as a programmer. They might seem hard at first but once you know the ins and outs of it, it will get much easier. A tree is nothing but a bunch of nodes hierarchically linked together.</p><p>Let us see how to perform In Order traversal on a tree. But why traverse a tree you might ask. One could traverse a tree to search for something among other things. But learning how to traverse a tree is also a great way to familiarize yourself with the tree data structure.</p><p>Let us now learn how In Order traversal works. In Order traversal means that we visit the nodes of a tree from left to right. The first node we visit with be the left most node of a tree and then its root or parent node and the right child node.</p><p>For example if our tree looks something like this:</p><pre>       1<br>     /   \<br>    6     4<br>   /<br>  8</pre><p>The first node that we will visit in our traversal is 8, then 6 then 1 and then 4.</p><p>Let us take a bigger tree as an example so we can better understand how in order traversal works.</p><pre>       1<br>     /   \<br>    6     4<br>   /  \<br>  8    5<br>      / \<br>     3   9</pre><p>In this case our traversed nodes will look something like: 8,6,3,5,9,1,4</p><p>We will be using stacks to help us traverse the tree.</p><h3>The Program</h3><p>The trick is to go the node to the farthest left and make you way back to the root node printing out the right and the parent node of the all the nodes.</p><p>We will put all the left nodes in the stack first. Once we hit the bottom i.e. once there are no more left nodes left we start printing out the nodes one by one and checking if the node has a right node. If it does we then again start storing all the left nodes of the right node we just encountered and the process goes on until the stack is empty.</p><h4>Step 1: Creating the stack and the switch</h4><pre>def inOrder(root):<br>    stack=[]<br>    switch=1    </pre><p>We will use a switch to kill the loop once the stack is empty and we have no more nodes left to traverse.</p><h4>Step 2: The loop</h4><pre>while(switch==1):<br>        if (root is not None):<br>            stack.insert(0,root)    <br>            root=root.left</pre><p>Here we are traversing the tree and stacking the left nodes as we go through them until be hit the bottom i.e. None.</p><h4>Step 3: Pop the node | Print it | Go to right node</h4><pre>while(switch==1):<br>        if (root is not None):<br>            stack.insert(0,root)    <br>            root=root.left<br>        else:    <br>            if (len(stack)&lt;=0):<br>                switch=0 <br>            else:<br>                root=stack.pop(0)<br>                print(root.info)<br>                root=root.right</pre><p>If the right node does not exists the current node will become null which will result in popping another node from the stack.</p><h3>The Program</h3><pre>def inOrder(root):<br>    stack=[]<br>    switch=1<br>    while(switch==1):<br>        if (root is not None):<br>            stack.insert(0,root)    <br>            root=root.left<br>        else:    <br>            if (len(stack)&lt;=0):<br>                switch=0 <br>            else:<br>                root=stack.pop(0)<br>                print(root.info)<br>                root=root.right</pre><p>And that’s about it. Now you know how In Order traversal works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4207d87dd33e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/in-order-traversal-using-stacks-python-4207d87dd33e">In Order Traversal Using Stacks (Python)</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Equalizing an array using python.]]></title>
            <link>https://medium.com/thebug/equalizing-an-array-using-python-2ebcb251dff5?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/2ebcb251dff5</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[equalizing-array]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Wed, 18 Jul 2018 11:07:21 GMT</pubDate>
            <atom:updated>2018-07-18T12:30:22.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-ycyrBhrvPMOyj8eAwQng.jpeg" /></figure><p>I stumbled upon this problem while browsing HackerRank. And I really enjoyed doing. If you don’t know what HackerRank is go check their website its an amazing resource to practice coding through completing challenges and competing with other people in the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhV105AX1GNhHhqc8ZunEg.png" /></figure><blockquote><strong><em>Credits:</em></strong><em> </em><a href="https://www.hackerrank.com/challenges/equality-in-a-array/problem"><em>https://www.hackerrank.com/challenges/equality-in-a-array/problem</em></a></blockquote><blockquote><strong>Author: </strong><a href="https://www.hackerrank.com/profile/muratekici">muratekici</a></blockquote><h3>The Problem</h3><p>Karl has an array of integers. He wants to reduce the array until all remaining elements are equal. Determine the fewest number of elements to delete to reach his goal.</p><p>For example, if his array is , <strong><em>arr=[1,2,2,3]</em></strong> we see that he can delete the <strong><em>2 </em></strong>elements <strong><em>1</em></strong> and <strong><em>3</em></strong> leaving <strong><em>arr=[2,2]</em></strong> . He could also delete both twos and either the <strong><em>1</em></strong> or the <strong><em>3</em></strong>, but that would take <strong><em>3</em></strong> deletions. The minimum number of deletions is <strong><em>2</em></strong>.</p><h3>The Solution</h3><p>Once you think about it, its quite simple you count the largest number of similar numbers and delete the rest. So how do we do it?</p><p><strong>Using dictionaries:</strong></p><p>We will use a dictionary to generate a <em>frequency histogram</em>:</p><pre>count=0<br>    G={}<br>    for i in arr:<br>        if i not in G:<br>            for j in arr:<br>                if i==j:<br>                    count=count+1 //counting similar elements<br>            G[i]=count //setting values<br>            count=0</pre><p>What this snippet of code does is, it first generates keys in the dictionary if the key is not already in there. Then it goes through the whole array counting all the similar elements and then sets the value of that key as the count.</p><p>Now comes the tricky part which is finding out which key has the largest value. Turns out there is an extremely easy way to do this!</p><pre>max_val=max(G, key=G.get)</pre><p>Where G is the dictionary and we use <strong><em>max() t</em></strong>o find out the key with the largest value. Once we have that we simply have to find out the value of the key and subtract the value from the length of the original array.</p><pre>return (len(arr)-G[max_val])</pre><h3><strong>The Code</strong></h3><pre>def equalizeArray(arr):<br>    count=0<br>    G={}<br>    for i in arr:<br>        if i not in G:<br>            for j in arr:<br>                if i==j:<br>                    count=count+1<br>            G[i]=count<br>            count=0<br>            <br>    max_val=max(G, key=G.get)<br>    return (len(arr)-G[max_val])</pre><p>And that’s it! You now know how to equalize the array! Congratulations!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ebcb251dff5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/equalizing-an-array-using-python-2ebcb251dff5">Equalizing an array using python.</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[String with unique characters using Python]]></title>
            <link>https://medium.com/thebug/string-with-unique-characters-using-python-5a53b3b4a7b7?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/5a53b3b4a7b7</guid>
            <category><![CDATA[string-unique-characters]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[unique]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Wed, 18 Jul 2018 09:28:28 GMT</pubDate>
            <atom:updated>2018-07-18T09:28:28.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8iCx0s02wMzzWpBXQcJHtw.jpeg" /></figure><p>Welcome to this super short article for a super short program. How to we check if all the characters in a given string are unique.</p><p>Here the normal way one would do it if one just started programming.</p><pre>def make_link(arr):<br>    count=0<br>    for i in range (len(arr)):<br>        value=arr[i]<br>        for j in range (len(arr)):<br>            if arr[j]==value:<br>               count=count+1<br>               if(count&gt;1):<br>                  return(&quot;Nopes&quot;)<br>        count=0</pre><p>But if you truly want to become a novice ninja coder of the highest order, you need to up your game!</p><h4>Presenting a simpler and easier way to do it!</h4><pre>def make_link(arr):<br>   <br>    G=[]<br>    for i in arr:<br>        if i not in G:<br>            G.append(i)</pre><pre>make_link(&#39;abcdefgha&#39;);</pre><p>We first create an empty array. We then loop through the string and append the elements to our empty array if its not already in there. And that&#39;s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xCqudGUaoQhb3XyfRMAOA.jpeg" /><figcaption>MIND=BLOWN!</figcaption></figure><p>We can then compare the length of our array and the original string and if they are not equal that means that the elements in the string are sadly not very unique!</p><pre>if len(G)!=len(arr):<br>        print(&quot;not unique&quot;)<br>    else:<br>        print(&quot;Unique!&quot;)</pre><p>Congratulations! You now know how to figure out if a string contains all unique characters and you are amazing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a53b3b4a7b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/string-with-unique-characters-using-python-5a53b3b4a7b7">String with unique characters using Python</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integers to Roman Numerals using JavaScript (the weird way)]]></title>
            <link>https://medium.com/thebug/integers-to-roman-numerals-using-javascript-the-weird-way-29f29a34966e?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/29f29a34966e</guid>
            <category><![CDATA[integers-to-roman]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[roman-numerals]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[integer]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Sat, 14 Jul 2018 15:03:20 GMT</pubDate>
            <atom:updated>2018-07-14T15:10:54.936Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dAAPF1jNVDLhjZ1DQS-gtw.jpeg" /></figure><p>You have probably seen countless ways in countless languages to convert Integers to Roman Numerals. Different people have different ways of understanding the same stuff, so here is one more way to do it! The program has been broken into several steps so its easier to understand. But the most important step is to actually know how to solve it yourself.</p><h3>Figure out how to do it.</h3><p>The roman number system works something like this:</p><p>1.You divide the number into Thousands, Hundreds, Tens and Ones.</p><p>2. Then you write down the corresponding values and add them.</p><p>Here’s a link to help you better understand how to convert integers to roman numerals: <a href="https://www.mathsisfun.com/roman-numerals.html">https://www.mathsisfun.com/roman-numerals.html</a></p><h3>Now that you understand how the roman numeral system works lets get our hands dirty.</h3><p><strong><em>See that 40 is XL and everything before that is X. i.e.</em></strong></p><p>30=XXX</p><p>20=XX</p><p>10=X</p><p><strong><em>The roman numeral follows the same pattern. here is another example:</em></strong></p><p>400 = CD</p><p><strong><em>Everything before that is C added over and over again</em></strong></p><p>300= CCC</p><p>200=CC</p><h3>Now that we see the pattern we can set up our function so we have less work to do in the later stages.</h3><h3>STEP 1: Setting stuff up</h3><p>Let’s start by setting up our function()!</p><pre>function convertToRoman (num)<br>{<br>    var roman={<br>        1:&quot;I&quot;, 4:&quot;IV&quot;, 5:&quot;V&quot;, 9:&quot;IX&quot;, 10:&quot;X&quot;, 40:&quot;XL&quot;, 50:&quot;L&quot;, 90:&quot;XC&quot;, 100:&quot;C&quot;, 400:&quot;CD&quot;, 500:&quot;D&quot;, 900:&quot;CM&quot;, 1000:&quot;M&quot;,<br>    }</pre><pre>var mul={<br>        1:1, 2:10, 3:100, 4:1000,<br>    }</pre><pre>var romanarr=[1,4,5,9,10,40,50,90,100,400,500,900,1000];</pre><pre>var arr=[];<br>var finalarr=[];<br>var str=num.toString().split(&quot;&quot;);</pre><p><strong><em>var roman: </em></strong>Contains references to the roman equivalent of the numbers we will use to convert the inters.</p><p><strong><em>var mul: </em></strong>Contains the numbers we will use to break down the integer.</p><pre>while(str.length&gt;0){<br>        for(var i =0;i&lt;str.length;i++){<br>            arr.push(str[0]*mul[str.length]);<br>            str.shift();<br>            }<br>        }<br>        i=0;</pre><p>Now we break the integer. We run a loop and check the length of the string and multiply with the corresponding number using the <strong><em>mul</em></strong> object that we set up. We then push the multiplied number to a new array and delete the element from the first array. We then repeat the process and get the other integers.</p><p>Let us assume that our input was 1942 the new array would look like [1000,900,10,4].</p><p>Now moving on to the most challenging and fun part of the program.</p><h3>STEP 2: Check if the number already exists</h3><pre>for(var i=0;i&lt;arr.length;i++){<br>        if (arr[i] in roman){<br>            finalarr.push(roman[arr[i]]);<br>        }</pre><h3>STEP 3: Check if the number is greater than 1000</h3><pre>else if(parseInt(arr[i])&gt;1000){<br>            <br>            largest=parseInt((arr[i].toString().split(&quot;&quot;)[0]));<br>            for(var d =1;d&lt;=largest;d++){<br>            finalarr.push(&quot;M&quot;);<br>            }</pre><h3>STEP 4: Check if the number is zero(this part is redundant but helps us better understand what is happening)</h3><pre>else if (parseInt(arr[i])===0){<br>            continue;</pre><h3>STEP 5: If the number doesn&#39;t fit any of these categories calculate the roman value of the number</h3><pre>else{<br>            var x = parseInt(arr[i]);<br>            while(x!=0){<br>                for(var j=0;j&lt;romanarr.length;j++){<br>                    if (x&lt;romanarr[j]){<br>                        finalarr.push(roman[romanarr[j-1]]);<br>                        x=x-(romanarr[j-1])<br>                        break;<br>                    }<br>                }<br>            j=0;<br>        }<br>    }</pre><p>Now that we have everything in <strong><em>finalarr </em></strong>the only thing we need to do is join the array!</p><p>And that&#39;s it! Congratulations you now know how to convert. For the full code visit my GitHub: <a href="https://github.com/Aakarshs/JavaScript_Projects/blob/master/arabictoroman.js">https://github.com/Aakarshs/JavaScript_Projects/blob/master/arabictoroman.js</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29f29a34966e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/integers-to-roman-numerals-using-javascript-the-weird-way-29f29a34966e">Integers to Roman Numerals using JavaScript (the weird way)</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When the clouds disappear]]></title>
            <link>https://medium.com/thebug/when-the-clouds-disappear-4a0fb7c6bd8f?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/4a0fb7c6bd8f</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[cybercrime]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Sat, 14 Jul 2018 14:37:07 GMT</pubDate>
            <atom:updated>2017-09-21T13:28:45.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPj54x6nDRnoMczJg1ZeOw.jpeg" /></figure><p>A survey by “Citrix” a software company, found that a paltry 16 percent of the 1000 participants knew what cloud computing stands for. Just over half of the respondents thought that the weather can interfere with cloud computing and a whopping 29 percent think that the “cloud” is an actual cloud. “Cloud computing” is the act of storing, managing and processing data online as opposed to on your physical computer or network. But what happens during a storm? Does it cost more to store data on Cirrostratus than on Stratocumulus? Or is it all just a petty sham created by the heavens to lure us in while they make it pour whenever they want to and mess with our data? Be it the nonchalant gesture pointing towards the sky that people from the IT department make while talking about the cloud or the very intelligent use of the word “cloud” with “computing,” the misperception surrounding the term “cloud computing” is quite reasonable.</p><p>Contrary to the widely held belief, Cloud computing isn’t anything new, and it’s not related to the odd white shapes usually seen in the sky. Cloud in the technology world refers to hundreds of computers stacked in a room divided into virtual servers that you or your company can access from anywhere. When someone looks for ways to hide a dead body on Google, their terminal sends packets of data containing the string of keywords to Google’s servers. The string of words is then processed on the cloud farms which compare the string for matching results and then send another packet of data back to the terminal. These clustered computers could be anywhere in the world. “Cloud computing” is just an industry slang which is used to define almost anything that uses these servers to run their applications. Gmail and Outlook are technically “cloud computing” personal communication management services.</p><p>Storing information locally is not a very efficient thing to do in the modern age of information. Using in-house storage and management services take up space, consume a lot of electricity and require timely maintenance. Using cloud computing saves power, administration costs, costs related to in-house cooling, and in turn offloading this management and dirty work to someone else saving precious capital and labor. In short, it saves you from having to apportion a room for horrid looking earsplitting mainframes and terminals, the time wasted in running anti-virus software, worrying about hard-drive crashes and the phlegmatic employee’s porn and illegal music collection on your company’s $50,000 computer.</p><p>The sole purpose of a business is to earn money, therefore spending substantial capital on maintaining IT infrastructure for in-house storage and processing defeats the purpose. Cloud computing is more cost-effective and reliable than in-house computing, and that is one of the key reasons for its swelling popularity. Most providers provide a guarantee with a service level agreement which guarantees 24x7 availability. Cloud computing also provides benefits such as quick failover mechanisms. For example, if a server fails, hosted applications and services can easily be transited to any of the available servers. Cloud computing lets the users focus on the business itself rather than spending time on technological jargon. Computing locally comes with its own set of problems including systems going out of date which can, in turn, compromise the security and reliability of the data. Using cloud computing saves money that instead might have been spent on upgrading the hardware and peripherals cutting down on upfront costs.</p><p>Cloud computing presents its users a lot of opportunities by providing a platform for their users to develop and implement new processes, systems, and offerings almost instantly which in turn make them more competitive. It also allows companies to buy only the services they want whenever they want them. Cloud computing simplifies and accelerates the process of incorporating new services and applications in one’s business. It opens up opportunities by providing designers and web developers new and different ways to sell their goods and services through cloud technology. Businesses and organizations can conduct business much more efficiently by analyzing and using big data through the cloud.</p><p>Cloud computing binds you into long-term often inflexible contracts and although cloud service providers can be good, efficient, and reliable, using cloud computing makes the users extremely dependent on the supplier. What if your service provider decides to shut down a service you’re using? Or what if some internal error in the system causes the service to shut down? Recently, something similar happened with a startup named CareSet which was using Google’s cloud platform services when it was alerted by Google that their own system apparently was sending “intrusion attacks” to third parties. Google warned CareSet that if the problem was not fixed, then it would block CareSet’s account. What actually happened was that Google misread some of CareSet’s own web traffic, suspecting evil intent when there was none. By the time the company deciphered Google’s email, three days had gone by, and Google shut them down. Big companies who use cloud computing platforms to process their data and storage often have billions of dollars riding on these services and could lose millions within a span of 5 minutes due to the shutdown of the service.</p><p>Another problem with cloud computing is that in 3rd world countries like India the internet prices are relatively high and the connection is highly unreliable which increases the cost of running and connecting to these cloud computing setups. Therefore, in these countries, cloud computing might not be an ideal solution.</p><p>Security is a major concern for people and businesses that use cloud computing. What keeps your data safe when it is remote and traveling back and forth over the internet? Privacy is a very complex issue. Some proponents of cloud computing might argue that the cloud services of these companies come with state of the art security to keep their everyday information safe and that the cloud-based systems are more secure than conventional ones. Buying Google’s, Amazon’s, or Microsoft’s cloud-based services affords users world-class expertise at keeping data safe. But is the aforementioned statement true? The idea of all data being stored and processed somewhere in the cloud seems magical, but it still is stored in a brick and mortar location, since every bit of data is stored in some form of a server farm/facility. The weakest elements in this scenario are the technicians who manage and operate the servers the people on the utmost top of corporate paradigm, i.e., the executives and the founders and co-founders, who have unrestricted access to all data. Humans are driven by individual needs and desires and can act independently; they can be bribed or threatened. Therefore, there is always the potential that someone somewhere has the power to compromise everything.</p><p>Companies like Google and Facebook store “big data,” i.e., data that they gather about people using their services. This data is comprised of people’s credit card numbers, search history, videos, photos, and even their online purchases which is all stored onto their cloud servers. While some Facebook and Google fanatics might argue that these companies are incredibly trustworthy and are using our data to provide us with better services, one question remains. What happens during a data breach? The “free” web-based services and apps that we use come at a very steep price which is the loss of privacy. But one must wonder, are we even entitled to privacy? Something similar happened when Equifax was hacked. The hack resulted in credit card data of thousands of people being leaked. Similar hacks have been coming at a greater rate than ever before. Earlier this year “WannaCry” ransomware cryptoworm targeted computers running Microsoft Windows by encrypting data and demanding ransom payments in Bitcoins and was shortly followed by a similar attack called the Petya ransomware attack.</p><p>Cloud is currently being used as a way to store and analyze big data, but in the future, cloud computing is predicted to evolve from data analytics to deep learning. Machine learning is the next level of programming which will be a big part of cloud computing. This will allow companies to go through and analyze data without much human effort. It will be able to understand complex concepts such as chaos theory and neural interactions and make decisions based on what the users want them to do, allowing developers to focus on creating new and innovative applications.</p><p>Storing data locally may seem too old school to some people, but the chances of things going wrong with cloud computing are exponential. Data breaches cost companies millions of dollars. Is going back to the old days of writing things on paper, using analog calculators and human resources to process data the safest way to go about things? Maybe not, but neither is the decision to hand your life and money to someone else on the internet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a0fb7c6bd8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/when-the-clouds-disappear-4a0fb7c6bd8f">When the clouds disappear</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding the missing number in the array]]></title>
            <link>https://medium.com/thebug/finding-the-missing-number-in-the-array-958f4aafae51?source=rss----8cbf93597b---4</link>
            <guid isPermaLink="false">https://medium.com/p/958f4aafae51</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[THEBUG]]></dc:creator>
            <pubDate>Sat, 14 Jul 2018 14:35:06 GMT</pubDate>
            <atom:updated>2018-07-14T14:35:06.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W2heEP5SKQg8bFS4whNo3A.jpeg" /></figure><p>Lets figure out how to find the missing number in the array. Lets say we have an array that starts from 1: [1,2,3,4,5,7,8]. We see that the missing number is 6. So how do we return the missing number?</p><p>STEP 1: Set up the function</p><pre>function missing(arr){}</pre><p>STEP 2: Create a variable that counts for you</p><pre>function missing(arr){<br>    var x=0;<br>}</pre><p>STEP 3: Create a loop that runs through the array</p><pre>function missing(arr){<br>    var x = 0;<br>    for(var i=0;i&lt;arr.length;i++){<br>}</pre><p>STEP 4: Use a counter and compare it to the elements of the array</p><pre>function missing(arr) {<br>    var x = 0;<br>    for (var i = 0; i &lt; arr.length; i++) {<br>        x = x + 1;<br>        if (arr[i] != x) {<br>            return(x);<br>        }<br>    }</pre><pre>}<br>missing([1, 2, 3, 4, 5, 6, 7, 8, 10])</pre><p>Thats it! If the counter is not equal to the corresponding element in the array then return the missing number!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=958f4aafae51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebug/finding-the-missing-number-in-the-array-958f4aafae51">Finding the missing number in the array</a> was originally published in <a href="https://medium.com/thebug">THEBUG</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>