<?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: Shivam Seth</title>
    <description>The latest articles on DEV Community by Shivam Seth (@shivamseth05).</description>
    <link>https://dev.to/shivamseth05</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%2F531940%2F670dee06-e8e4-4830-a1d4-a09c869d3daf.jpeg</url>
      <title>DEV Community: Shivam Seth</title>
      <link>https://dev.to/shivamseth05</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivamseth05"/>
    <language>en</language>
    <item>
      <title>Water the plants complete solution with full logic in O(n), 28 days solution .(java)</title>
      <dc:creator>Shivam Seth</dc:creator>
      <pubDate>Mon, 22 Feb 2021 19:22:23 +0000</pubDate>
      <link>https://dev.to/shivamseth05/water-the-plants-complete-solution-with-full-logic-in-o-n-28-days-solution-of-gfg-java-373h</link>
      <guid>https://dev.to/shivamseth05/water-the-plants-complete-solution-with-full-logic-in-o-n-28-days-solution-of-gfg-java-373h</guid>
      <description>&lt;p&gt;Water the plants complete solution with full logic in O(n), 28 days solution of GFG.(java)&lt;/p&gt;

&lt;p&gt;input = [2,3,4,-1,2,0,0,-1,0]&lt;br&gt;
output [-1]&lt;br&gt;
input = [-1,-1,2,2,0,0]&lt;/p&gt;

&lt;p&gt;//code &lt;br&gt;
import java.util.*;&lt;br&gt;
class ONE {&lt;br&gt;
    int min_sp(int gal[], int n)&lt;br&gt;
    {&lt;br&gt;
        int arr[] = new int [n];&lt;br&gt;
        Arrays.fill(arr, -1);&lt;br&gt;
        for (int i=0;i&amp;lt;n;++i)&lt;br&gt;
        {&lt;br&gt;
            // System.out.println("its n "+n);&lt;br&gt;
            if (gal[i]==0)&lt;br&gt;
            {&lt;br&gt;
                // System.out.println("its arr[i] "+arr[i]);&lt;br&gt;
                arr[i]=Math.max(arr[i],i);&lt;br&gt;
                continue;&lt;br&gt;
            }&lt;br&gt;
            if (gal[i]!=-1)&lt;br&gt;
            {&lt;br&gt;
                int k=i+gal[i];&lt;br&gt;
                // System.out.println("its k "+k);&lt;br&gt;
                // int j=max (0,i-gal[i]);&lt;br&gt;
                int j=Math.max(0,i-gal[i]);&lt;br&gt;
                // System.out.println("its j "+j);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            for(int sp = j;sp&amp;lt;=Math.min(n,k);++sp)
                {if(sp==n)
            continue;
                arr[sp]=Math.max(k,arr[sp]);}
        }
    }
    int c =0,i=0;
    while(i&amp;lt;n)
    {
        // System.out.println("its i and n "+i+" "+n);
        // System.out.println("its i and n "+i+" "+arr[i]);

        if (i==-1||arr[i]==-1)
        return -1;
        ++c;
        i=arr[i]+1;
    }
    return c;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;public static void main(String[] arr)&lt;br&gt;
{&lt;br&gt;
    //  Scanner in = new Scanner(System.in);&lt;br&gt;
    int gal[] ={2,3,4,-1,2,0,0,-1,0};&lt;br&gt;
    ONE s = new ONE();&lt;br&gt;
    int n=gal.length;&lt;br&gt;
    System.out.print(s.min_sp(gal,n));&lt;br&gt;
}&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>
Complete the sockMerchant function with python.</title>
      <dc:creator>Shivam Seth</dc:creator>
      <pubDate>Sun, 10 Jan 2021 19:53:44 +0000</pubDate>
      <link>https://dev.to/shivamseth05/complete-the-sockmerchant-function-below-416c</link>
      <guid>https://dev.to/shivamseth05/complete-the-sockmerchant-function-below-416c</guid>
      <description>&lt;p&gt;Alex works at a clothing store. There is a large pile of socks that must be paired by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.&lt;br&gt;
Complete the sockMerchant function in the editor below. It must return an integer representing the number of matching pairs of socks that are available.&lt;/p&gt;

&lt;p&gt;sockMerchant has the following parameter(s):&lt;/p&gt;

&lt;p&gt;n: the number of socks in the pile&lt;br&gt;
ar: the colors of each sock&lt;/p&gt;

&lt;h1&gt;
  
  
  Complete the sockMerchant function below.
&lt;/h1&gt;

&lt;p&gt;def sockMerchant(n, ar):&lt;br&gt;
    pears = 0&lt;br&gt;
    color = set()&lt;br&gt;
    for i in range(len(ar)):&lt;br&gt;
        if ar[i] not in color:&lt;br&gt;
            color.add(ar[i])&lt;br&gt;
        else:&lt;br&gt;
            pears += 1 &lt;br&gt;
            color.remove(ar[i])&lt;br&gt;
    return pears&lt;br&gt;
if &lt;strong&gt;name&lt;/strong&gt; == '&lt;strong&gt;main&lt;/strong&gt;':&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n = int(input())

ar = list(map(int, input().rstrip().split()))
ar.sort()


result = sockMerchant(n, ar)
print(result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>sockmerchant</category>
      <category>python</category>
    </item>
  </channel>
</rss>
