<?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 Viswanath Nagarajan on Medium]]></title>
        <description><![CDATA[Stories by Viswanath Nagarajan on Medium]]></description>
        <link>https://medium.com/@vish9940?source=rss-5c296d0a09cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JAEhd8cypFn-8P9t_C5gow@2x.jpeg</url>
            <title>Stories by Viswanath Nagarajan on Medium</title>
            <link>https://medium.com/@vish9940?source=rss-5c296d0a09cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:46:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vish9940/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[448. Find All Numbers Disappeared in an Array]]></title>
            <link>https://medium.com/@vish9940/448-find-all-numbers-disappeared-in-an-array-d52f0a97b0c6?source=rss-5c296d0a09cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d52f0a97b0c6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Viswanath Nagarajan]]></dc:creator>
            <pubDate>Fri, 08 Jul 2022 17:59:58 GMT</pubDate>
            <atom:updated>2022-07-08T17:59:58.287Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an array nums of n integers where nums[i] is in the range [1, n], return <em>an array of all the integers in the range</em> [1, n] <em>that do not appear in</em> nums.</p><p><strong>Example 1:</strong></p><pre><strong>Input:</strong> nums = [4,3,2,7,8,2,3,1]<br><strong>Output:</strong> [5,6]</pre><p><strong>Example 2:</strong></p><pre><strong>Input:</strong> nums = [1,1]<br><strong>Output:</strong> [2]</pre><p>The approach and the idea behind the code is explained after the code,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59cb7cabc84d3abaeb83f075d020e377/href">https://medium.com/media/59cb7cabc84d3abaeb83f075d020e377/href</a></iframe><p><em>Runtime Complexity:</em></p><p><em>O(n) — because we run a for loop and take the absolute of indices and subtract 1 from each element. Because array of length 8 contains</em></p><p><em>8 elements and if you subtract 8 with 1, we get 7 which is the last index in our array since it starts from 0 index. We traverse and subtract 1 with</em></p><p><em>every element and go to the particular index and set it to negative. We do this for ’n’ elements and we finally run a for loop</em></p><p><em>to check the positive numbers and append it to result array. We then finally return the result.</em></p><p><em>Space Complexity: O(1) — because the array length is fixed and missing numbers are always less than ’n’ so we append only few elements to it. Worst case can be O(N) if all elements are added to result array.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d52f0a97b0c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leetcode-28 Implement strStr()]]></title>
            <link>https://medium.com/@vish9940/leetcode-28-implement-strstr-3edef50969cc?source=rss-5c296d0a09cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3edef50969cc</guid>
            <category><![CDATA[substring]]></category>
            <category><![CDATA[strstr]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[substring-search]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <dc:creator><![CDATA[Viswanath Nagarajan]]></dc:creator>
            <pubDate>Wed, 25 May 2022 19:13:08 GMT</pubDate>
            <atom:updated>2022-05-25T19:13:08.780Z</atom:updated>
            <content:encoded><![CDATA[<p>Implement <a href="http://www.cplusplus.com/reference/cstring/strstr/">strStr()</a>.</p><p>Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.</p><p><strong>Clarification:</strong></p><p>What should we return when needle is an empty string? This is a great question to ask during an interview.</p><p>For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C&#39;s <a href="http://www.cplusplus.com/reference/cstring/strstr/">strstr()</a> and Java&#39;s <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)">indexOf()</a>.</p><p><strong>Example 1:</strong></p><pre><strong>Input:</strong> haystack = &quot;hello&quot;, needle = &quot;ll&quot;<br><strong>Output:</strong> 2</pre><p><strong>Example 2:</strong></p><pre><strong>Input:</strong> haystack = &quot;aaaaa&quot;, needle = &quot;bba&quot;<br><strong>Output:</strong> -1</pre><p><strong>Constraints:</strong></p><ul><li>1 &lt;= haystack.length, needle.length &lt;= 104</li><li>haystack and needle consist of only lowercase English characters.</li></ul><p><strong>Solution:</strong></p><pre>class Solution:<br>    def strStr(self, haystack: str, needle: str) -&gt; int:<br>        if needle in haystack:<br>            result = haystack.find(needle)<br>        else:<br>            return -1<br>        return result</pre><p>In the given problem, we are asked to find the first index of a substring present in a string. We can use a built-in function called <strong>find() </strong>which returns the index of the first occurrence of a substring in a string. We use ‘if’ condition to check whether the needle is in haystack and perform find() operation else if the needle is not in haystack, we return -1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3edef50969cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>