<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: harshdsdh</title>
    <description>The latest articles on DEV Community by harshdsdh (@harsh).</description>
    <link>https://dev.to/harsh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F166797%2Fa771d952-48ce-4c41-aad6-6fcedbd47135.png</url>
      <title>DEV Community: harshdsdh</title>
      <link>https://dev.to/harsh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harsh"/>
    <language>en</language>
    <item>
      <title>ember dependencies</title>
      <dc:creator>harshdsdh</dc:creator>
      <pubDate>Sun, 21 Jun 2020 18:15:55 +0000</pubDate>
      <link>https://dev.to/harsh/ember-dependencies-4ibh</link>
      <guid>https://dev.to/harsh/ember-dependencies-4ibh</guid>
      <description>&lt;p&gt;hey developers. good morning!&lt;br&gt;
i have a small question. when i install dependencies using 'npm install' it works but then when i do 'ember serve' it gives an error asking me to 'Run &lt;code&gt;yarn&lt;/code&gt; to install missing dependencies.' so my question is what am i doing wrong here. if i make sure that i only have npm or yarn on my system then will it work or ember requires both npm and yarn to install its dependencies?&lt;/p&gt;

</description>
      <category>ember</category>
    </item>
    <item>
      <title>The curious case of multiple solutions. #1 maximum sub array problem</title>
      <dc:creator>harshdsdh</dc:creator>
      <pubDate>Sat, 22 Feb 2020 00:07:59 +0000</pubDate>
      <link>https://dev.to/harsh/the-curious-case-of-multiple-solutions-1-maximum-sub-array-problem-40ka</link>
      <guid>https://dev.to/harsh/the-curious-case-of-multiple-solutions-1-maximum-sub-array-problem-40ka</guid>
      <description>&lt;p&gt;This is one of the basic questions covered in every data structures and algorithms class and book. &lt;br&gt;
The problem statement is like there is an array with positive and negative numbers and we need to find the maximum sum of a sub array. I was recently asked this question in an interview and although I have seen this a million times before I couldn’t come up with multiple solutions. I could only code out one method. So I thought to write this blog post as to make it easy for me to remember the solutions as well as anyone else who might also know only one way to solve the problem. &lt;/p&gt;

&lt;p&gt;1) divide and conquer&lt;/p&gt;

&lt;p&gt;In this we divide the problem into smaller problems then we solve the smaller problems and combine them to find our answer. in case of divide and conquer &lt;br&gt;
 a. we will first find the max sum in the left sub array A[low..mid]&lt;br&gt;
 b. then we will find the max sum in the right sub array A[mid..high]&lt;br&gt;
 c. then we find the max sum in the sub array crossing the mid point A[i..mid..j]. where low &amp;lt;= i &amp;lt;= mid &amp;lt; j &amp;lt;= high.&lt;/p&gt;

&lt;p&gt;for this method the running time will be O(NlogN)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def maxSubArray(self, nums: List[int]) -&amp;gt; int:

        def cross(arr,low,high,mid):
            s=0
            max_sum_left = -float('inf')
            for i in range(mid,low-1,-1):
                s+=arr[i]
                if s&amp;gt;max_sum_left:
                    max_sum_left=s
            s=0
            max_sum_right=-float('inf')
            for i in range(mid+1,high+1):
                s+=arr[i]
                if s&amp;gt;max_sum_right:
                    max_sum_right = s
            return max_sum_left + max_sum_right

        def helper(arr,low,high):

            if low==high:
                return arr[low]
            mid = (low+high)//2
            sum_left = helper(nums,low,mid)
            sum_right = helper(nums,mid+1,high)
            sum_cross = cross(arr,low,high,mid)
            return max(sum_left,sum_right,sum_cross)

        return helper(nums,0,len(nums)-1)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;2) greedy method&lt;/p&gt;

&lt;p&gt;This one says that we add the next number to my current sum and then check if my sum has increased or not. i.e suppose we have a current_sum and we encounter a new number,num then current_sum = max(current_sum+num , num) . for this method the running time will be O(n) as it takes only one linear  search in the array to find the answer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def maxSubArray(self, nums: List[int]) -&amp;gt; int:

        curr_sol = s = nums[0]
#start with the first number in the array

        for num in nums[1:]:
            curr_sol = max(curr_sol+num,num) #check if adding a new number makes sense
            s = max(curr_sol, s)
        return s #return the max sum found in the array
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;3) dynamic programming&lt;/p&gt;

&lt;p&gt;(i hate this topic in interviews) &lt;br&gt;
In this we are modifying the existing array such that if we find that a previous number is positive then we add that to current number keeping track of max sum found till then. Time complexity here is also O(n) as we only need one linear search to find the answer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def maxSubArray(self, nums: List[int]) -&amp;gt; int:
#start with the first number
        max_sum=nums[0]

        for i in range(1,len(nums)):
#check the previous number and add to current number if its positive
            if nums[i-1]&amp;gt;0:
                nums[i]+=nums[i-1]
#keep track of max_sum found
            max_sum = max(nums[i],max_sum)
        return max_sum
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>dynamicprogramming</category>
      <category>greedy</category>
      <category>maximumsubarray</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
