<?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 Techiegirl on Medium]]></title>
        <description><![CDATA[Stories by Techiegirl on Medium]]></description>
        <link>https://medium.com/@alishafire?source=rss-a02146792e30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YlcLc3i5kE3y_OOv.jpg</url>
            <title>Stories by Techiegirl on Medium</title>
            <link>https://medium.com/@alishafire?source=rss-a02146792e30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:46:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alishafire/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[Striver sde sheet day 1 problem 6]]></title>
            <link>https://medium.com/@alishafire/striver-sde-sheet-day-1-problem-6-e1ace9e55448?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1ace9e55448</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 16:01:18 GMT</pubDate>
            <atom:updated>2024-04-11T16:01:18.983Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock/submissions/1229595446/">https://leetcode.com/problems/best-time-to-buy-and-sell-stock/submissions/1229595446/</a></p><ol><li>TLE, brute force</li></ol><pre>class Solution:<br>    def maxProfit(self, prices: List[int]) -&gt; int:<br>        buyprice=prices[0]<br>        maxprofit=0<br>        for i in range(0,len(prices)):<br>            buyprice=prices[i]<br>            for j in range(i+1,len(prices)):<br>                sellprice=prices[j]<br>                maxprofit=max(maxprofit,sellprice-buyprice)<br>        return maxprofit</pre><p>2. Optimal</p><pre>class Solution:<br>    def maxProfit(self, prices: List[int]) -&gt; int:<br>        minprice=float(&#39;inf&#39;)<br>        maxprice=0<br>        for i in range(len(prices)):<br>            minprice=min(prices[i],minprice)<br>            maxprice=max(maxprice,prices[i]-minprice)<br>        return maxprice</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1ace9e55448" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Striver sde sheet day 1 problem 5]]></title>
            <link>https://medium.com/@alishafire/striver-sde-sheet-day-1-problem-5-ab978ac0b873?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab978ac0b873</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 15:23:31 GMT</pubDate>
            <atom:updated>2024-04-11T15:23:31.682Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/sort-colors/solutions/1137080/sort-0s-1s-and-2s/">https://leetcode.com/problems/sort-colors/solutions/1137080/sort-0s-1s-and-2s/</a></p><pre>class Solution:<br>    def sortColors(self, nums: List[int]) -&gt; None:<br>        &quot;&quot;&quot;<br>        Do not return anything, modify nums in-place instead.<br>        &quot;&quot;&quot;<br>        arr=nums<br>        n=len(nums)<br>        low=0<br>        mid=0<br>        high=n-1<br>        while mid&lt;=high:<br>            if arr[mid]==0:<br>                arr[low],arr[mid]=arr[mid],arr[low]<br>                low+=1<br>                <br>            if arr[mid]==2:<br>                arr[high],arr[mid]=arr[mid],arr[high]<br>                high-=1<br>            else:<br>                mid+=1<br>                </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab978ac0b873" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Striver’s sheet day 1 problem 4]]></title>
            <link>https://medium.com/@alishafire/strivers-sheet-day-1-problem-4-a7f8df727012?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7f8df727012</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 15:05:07 GMT</pubDate>
            <atom:updated>2024-04-11T15:05:07.062Z</atom:updated>
            <content:encoded><![CDATA[<p>https://leetcode.com/problems/maximum-subarray/</p><ol><li>Brute force. Not all test cases pass. TLE</li></ol><pre>class Solution:<br>    def maxSubArray(self, nums: List[int]) -&gt; int:<br>        maxsum=nums[0]<br>        for i in range(len(nums)):<br>            sum1=nums[i]<br>            if sum1&gt;maxsum:<br>                maxsum=sum1<br>            for j in range(i+1,len(nums)):<br>                sum1+=nums[j]<br>                if sum1&gt;maxsum:<br>                    maxsum=sum1<br>        return maxsum<br>                <br>        </pre><ol><li>Optimal solution.</li></ol><pre>class Solution:<br>    def maxSubArray(self, nums: List[int]) -&gt; int:<br>        maxsum=nums[0]<br>        sum1=0<br>        for i in range(len(nums)):<br>            sum1+=nums[i]<br>            if sum1&gt;maxsum:<br>                maxsum=sum1<br>        <br>            if sum1&lt;0:<br>                sum1=0<br>        return maxsum<br>                <br>        </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7f8df727012" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Striver’s sde sheet day1 problem 3]]></title>
            <link>https://medium.com/@alishafire/strivers-sde-sheet-day1-problem-3-14b79acae3a9?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/14b79acae3a9</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 16:32:34 GMT</pubDate>
            <atom:updated>2024-03-28T16:32:34.449Z</atom:updated>
            <content:encoded><![CDATA[<p>Striver’s sde sheet day1 problem 3</p><p>https://leetcode.com/problems/next-permutation/</p><pre>class Solution:<br>    def nextPermutation(self, nums: List[int]) -&gt; None:<br>        &quot;&quot;&quot;<br>        Do not return anything, modify nums in-place instead.<br>        &quot;&quot;&quot;<br>        n=len(nums)<br>        index=-1<br>        a=nums<br>        for i in range(n-2,-1,-1):<br>            if(a[i]&lt;a[i+1]):<br>                index=i<br>                break<br>        if(index==-1):<br>            nums=nums.reverse()<br>            return nums<br>        else:<br>            for j in range(n-1,-1,-1):<br>                if(nums[j]&gt;nums[i]):<br>                    nums[index],nums[j]=nums[j],nums[index]<br>                    break<br>            nums[index+1:]=reversed(nums[index+1:])<br>            return nums<br><br>        <br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14b79acae3a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Striver’s sde sheet day 1 problem 2]]></title>
            <link>https://medium.com/@alishafire/strivers-sde-sheet-day-1-problem-2-25e3bbbd742c?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/25e3bbbd742c</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 16:31:28 GMT</pubDate>
            <atom:updated>2024-03-28T16:31:28.888Z</atom:updated>
            <content:encoded><![CDATA[<p>Striver’s sde sheet day 1 problem 2</p><p>https://leetcode.com/problems/pascals-triangle/</p><pre>class Solution:<br>    def ncr(self,n,r):<br>        res=1<br>        for i in range(r):<br>            res=res*(n-i)<br>            res=res//(i+1)<br>        return res<br>    def generate(self, numRows: int) -&gt; List[List[int]]:<br>        ans=[]<br>        n=numRows<br>        for i in range(1,n+1):<br>            tmp_list=[]<br>            for j in range(1,i+1):<br>                tmp_list.append(self.ncr(i-1,j-1))<br>            ans.append(tmp_list)<br>        return ans<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25e3bbbd742c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Level order traversal of binary tree(solved)-2 ways through queue and recursion]]></title>
            <link>https://medium.com/@alishafire/level-order-traversal-of-binary-tree-solved-2-ways-through-queue-and-recursion-1355440d93ac?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/1355440d93ac</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Wed, 27 Mar 2024 11:04:29 GMT</pubDate>
            <atom:updated>2024-03-27T11:04:29.231Z</atom:updated>
            <content:encoded><![CDATA[<p>Level order traversal of binary tree(solved)-2 ways through queue and recursion</p><p>Through recursion</p><pre># Definition for a binary tree node.<br># class TreeNode:<br>#     def __init__(self, val=0, left=None, right=None):<br>#         self.val = val<br>#         self.left = left<br>#         self.right = right<br>class Solution:<br>    def newlevelOrder(self,root,dict2,curr_level):<br>        if root==None:<br>            return dict2<br>        if curr_level not in dict2:<br>            dict2[curr_level]=[]<br>        dict2[curr_level].append(root.val)<br>        if root.left!=None:<br>            self.newlevelOrder(root.left,dict2,curr_level+1)<br>        if root.right!=None:<br>            self.newlevelOrder(root.right,dict2,curr_level+1)<br>        return dict2<br><br><br>    def levelOrder(self, root: Optional[TreeNode]) -&gt; List[List[int]]:<br>        &#39;&#39;&#39;<br>        q=[]<br>        ans=[]<br>        if root is None:<br>            return root<br>        q.append(root)<br>        while len(q)&gt;0:<br>            temp=q.pop()<br>            if temp is not None:<br>                ans.append(temp.val)<br>                if temp.left!=&quot;null&quot;:<br>                    q.append(temp.left)<br>                if temp.right!=&quot;null&quot;:<br>                    q.append(temp.right)<br>        return ans<br>        &#39;&#39;&#39;<br>        final_dict=dict()<br>        x=self.newlevelOrder(root,final_dict,0)<br>        final_list=[]<br>        for i in x.keys():<br>            final_list.append(x[i])<br>        return final_list<br></pre><p>Through queue</p><pre># Definition for a binary tree node.<br># class TreeNode:<br>#     def __init__(self, val=0, left=None, right=None):<br>#         self.val = val<br>#         self.left = left<br>#         self.right = right <br>from collections import deque<br>class Solution:<br>    def levelOrder(self, root: Optional[TreeNode]) -&gt; List[List[int]]:<br>        &#39;&#39;&#39;<br>        final_list=[]<br>        q=deque()<br>        q.append(root)<br>        while len(q)&gt;0:<br>            x=[]<br>            a=q.popleft()<br>            x.append(a)<br>            q.append(a.left)<br>            q.append(a.right)<br><br>        return []<br>        &#39;&#39;&#39;<br>        if root is None:<br>            return root<br>        queue=[]<br>        return_list=[]<br>        queue.append(root)<br>        while len(queue)&gt;0:<br>            ans=[]<br>            l=len(queue)<br>            while l&gt;0:<br>                x=queue.pop(0)<br>                l-=1<br>                ans.append(x.val)<br>                if x.left is not None:<br>                    queue.append(x.left)<br>                if x.right is not None:<br>                    queue.append(x.right)<br>            return_list.append(ans)<br>        return return_list<br>        <br>        <br><br>        </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1355440d93ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximum depth of binary tree using recursion]]></title>
            <link>https://medium.com/@alishafire/maximum-depth-of-binary-tree-using-recursion-0825b8a57a74?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/0825b8a57a74</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 16:26:32 GMT</pubDate>
            <atom:updated>2024-03-20T16:26:32.943Z</atom:updated>
            <content:encoded><![CDATA[<p>Maximum depth of binary tree using recursion</p><p>https://leetcode.com/problems/maximum-depth-of-binary-tree/submissions/1209250223/</p><pre># Definition for a binary tree node.<br># class TreeNode:<br>#     def __init__(self, val=0, left=None, right=None):<br>#         self.val = val<br>#         self.left = left<br>#         self.right = right<br>class Solution:<br>    def maxdepth1(self,root,curr_level,max1):<br>        max1=max(max1,curr_level)<br>        if root.left!=None:<br>            x=self.maxdepth1(root.left,curr_level+1,max1)<br>            max1=max(x,max1)<br>        if root.right!=None:<br>            y=self.maxdepth1(root.right,curr_level+1,max1)<br>            max1=max(max1,y)<br>        return max1<br>        <br><br>    def maxDepth(self, root: Optional[TreeNode]) -&gt; int:<br>        if root==None:<br>            return 0<br>        return self.maxdepth1(root,1,1)<br>        <br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0825b8a57a74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Print all paths from node to leaf in any order]]></title>
            <link>https://medium.com/@alishafire/print-all-paths-from-node-to-leaf-in-any-order-9e88a598c7dd?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e88a598c7dd</guid>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 10:34:45 GMT</pubDate>
            <atom:updated>2024-03-20T10:34:45.304Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/binary-tree-paths/">https://leetcode.com/problems/binary-tree-paths/</a></p><p>We use backtracking and recursion to explore all paths in this code.</p><pre># Definition for a binary tree node.<br># class TreeNode:<br>#     def __init__(self, val=0, left=None, right=None):<br>#         self.val = val<br>#         self.left = left<br>#         self.right = right<br>class Solution:<br>    def binarypath(self,root,result,final,iter):<br>        #print(&quot;current root&quot;,root.val)<br>        #if(iter==1):<br>            #result+=str(root.val)<br>            #x=result<br>            <br>        if(root==None):<br>            return final<br>        if root.left==None and root.right==None:<br>            #result+=&quot;-&gt;&quot;<br>            if iter&gt;1:<br>                result+=&quot;-&gt;&quot;<br>                result+=str(root.val)<br>            final.append(result)<br>        else:<br>            print(&quot;here in else loop&quot;)<br>            x=result<br>            #result+=&quot;-&gt;&quot;<br>            if(iter&gt;1):<br>                result+=&quot;-&gt;&quot;<br>                result+=str(root.val)<br>            print(&quot;result is&quot;,result)<br>            if(root.left!=None):<br>                self.binarypath(root.left,result,final,iter+1)<br>        <br>            if root.right!=None:<br>                self.binarypath(root.right,result,final,iter+1)<br>        return final<br><br><br>    def binaryTreePaths(self, root: Optional[TreeNode]) -&gt; List[str]:<br>        result=&quot;&quot;<br>        final=[]<br>        iter=1<br>        if(root!=None):<br>            result+=str(root.val)<br>        final=self.binarypath(root,result,final,iter<br>        )<br>        return final<br>        <br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e88a598c7dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Sum (with two cases)]]></title>
            <link>https://medium.com/@alishafire/two-sum-with-two-cases-437ace093470?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/437ace093470</guid>
            <category><![CDATA[data-structures-in-python]]></category>
            <category><![CDATA[two-sum]]></category>
            <category><![CDATA[dsa-training]]></category>
            <category><![CDATA[two-pointers]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 07:40:18 GMT</pubDate>
            <atom:updated>2024-03-20T07:40:18.515Z</atom:updated>
            <content:encoded><![CDATA[<p>Case 1: array sorted</p><p><a href="https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/">https://leetcode.com/problems/two-sum-ii-input-array-is-sorted</a></p><p>Two pointer techniques are used here.</p><pre>class Solution:<br>    def twoSum(self, numbers: List[int], target: int) -&gt; List[int]:<br>        i=0<br>        n=len(numbers)<br>        j=n-1<br>        while i&lt;j:<br>            if(numbers[i]+numbers[j]==target):<br>                return [i+1,j+1]<br>            elif(numbers[i]+numbers[j]&lt;target):<br>                i+=1<br>            else:<br>                j-=1<br>        return [-1,-1]<br></pre><p>Case 2: array not sorted</p><p>https://leetcode.com/problems/two-sum/</p><p>We’ll use a hashmap here to keep track of elements and their indices. We will check if a corresponding element to the number to be checked currently exists in the hashmap.</p><pre>class Solution:<br>    def twoSum(self, nums: List[int], target: int) -&gt; List[int]:<br>    <br>        i=0<br>        n=len(nums)<br>        j=n-1<br>        x=dict()<br>        for i in range(n):<br>            if target-nums[i] in x:<br>                return [i,x[target-nums[i]]]<br>            x[nums[i]]=i<br>        return [-1,-1]<br><br>        <br>                <br>        <br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=437ace093470" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Striver’s sde sheet day 1 problem 1]]></title>
            <link>https://medium.com/@alishafire/strivers-sde-sheet-day-1-problem-1-a3c4eb1206e6?source=rss-a02146792e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3c4eb1206e6</guid>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[striver-sheet]]></category>
            <category><![CDATA[sde-interview]]></category>
            <category><![CDATA[strivers-sde-sheet]]></category>
            <category><![CDATA[dsa-training]]></category>
            <dc:creator><![CDATA[Techiegirl]]></dc:creator>
            <pubDate>Fri, 23 Feb 2024 05:25:25 GMT</pubDate>
            <atom:updated>2024-02-23T05:25:25.863Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Problem Statement:</strong> Given a matrix if an element in the matrix is 0 then you will have to set its entire column and row to 0 and then return the matrix</p><p>Naive solution,with runtime O(n**2) and space also O(n)</p><pre>class Solution:<br>    def setZeroes(self, matrix: List[List[int]]) -&gt; None:<br>        &quot;&quot;&quot;<br>        Do not return anything, modify matrix in-place instead.<br>        &quot;&quot;&quot;<br>        m=len(matrix)<br>        n=len(matrix[0])<br>        #print(m,n)<br>        a=set()<br>        for i in range(0,m):<br>            for j in range(0,n):<br>                if matrix[i][j]==0:<br>                    a.add((i,j))<br>        #print(a)<br>        for x in a:<br>            p=x[0]<br>            q=x[1]<br>            for j in range(0,n):<br>                matrix[p][j]=0<br>            for i in range(0,m):<br>                matrix[i][q]=0<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*CJhknluL6wfoMPX4MI6xRg.png" /></figure><p>Now for the optimal solution</p><pre>def zeroMatrix(matrix, n, m):<br>    row = [0] * n  # row array<br>    col = [0] * m  # col array<br><br>    # Traverse the matrix:<br>    for i in range(n):<br>        for j in range(m):<br>            if matrix[i][j] == 0:<br>                # mark ith index of row wih 1:<br>                row[i] = 1<br><br>                # mark jth index of col wih 1:<br>                col[j] = 1<br><br>    # Finally, mark all (i, j) as 0<br>    # if row[i] or col[j] is marked with 1.<br>    for i in range(n):<br>        for j in range(m):<br>            if row[i] or col[j]:<br>                matrix[i][j] = 0<br><br>    return matrix<br><br><br>if __name__ == &quot;__main__&quot;:<br> matrix = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]<br> n = len(matrix)<br> m = len(matrix[0])<br> ans = zeroMatrix(matrix, n, m)<br><br> print(&quot;The Final matrix is:&quot;)<br> for row in ans:<br>     for ele in row:<br>         print(ele, end=&quot; &quot;)<br>     print()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3c4eb1206e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>