<?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: Shashi Vardhan</title>
    <description>The latest articles on DEV Community by Shashi Vardhan (@notyetknown).</description>
    <link>https://dev.to/notyetknown</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%2F808555%2F6575783d-fc31-4741-8921-ee22c5d5ad3d.jpg</url>
      <title>DEV Community: Shashi Vardhan</title>
      <link>https://dev.to/notyetknown</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/notyetknown"/>
    <language>en</language>
    <item>
      <title>Bit Counting Codewars</title>
      <dc:creator>Shashi Vardhan</dc:creator>
      <pubDate>Thu, 03 Feb 2022 14:29:56 +0000</pubDate>
      <link>https://dev.to/notyetknown/bit-counting-codewars-19im</link>
      <guid>https://dev.to/notyetknown/bit-counting-codewars-19im</guid>
      <description>&lt;p&gt;Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative.&lt;/p&gt;

&lt;p&gt;Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case&lt;/p&gt;

&lt;p&gt;Code(Java)&lt;br&gt;
&lt;/p&gt;

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

     {

         int count=0;

         String BinaryValues=Integer.toBinaryString(n);

         //System.out.println(BinaryValues);

         for(int i=0;i&amp;lt;BinaryValues.length();i++)

         {

              if(BinaryValues.charAt(i)=='1')

              {

                  count++;

              }

         }

         return count;

     }

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

&lt;/div&gt;



&lt;p&gt;Solution 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static int countBits(int n){



    return Integer.bitCount(n);

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

&lt;/div&gt;



&lt;p&gt;More at : &lt;a href="https://onlylang.blogspot.com/"&gt;https://onlylang.blogspot.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>codewars</category>
      <category>programming</category>
    </item>
    <item>
      <title>Popular Contest</title>
      <dc:creator>Shashi Vardhan</dc:creator>
      <pubDate>Thu, 03 Feb 2022 09:06:53 +0000</pubDate>
      <link>https://dev.to/notyetknown/popular-contest-1d3n</link>
      <guid>https://dev.to/notyetknown/popular-contest-1d3n</guid>
      <description>&lt;p&gt;Codeground is hosting the World's largest coding competition. There are N participants in the contest sitting in a single row.&lt;/p&gt;

&lt;p&gt;The energy of i’th participant from left is A[i]. To raise the popularity of the contest, some rules are added.&lt;/p&gt;

&lt;p&gt;A participant numbered i will challenge other participant numbered j if and only if j is ahead of him (j&amp;gt;i) and the distance between i and j (j-i) is prime.&lt;/p&gt;

&lt;p&gt;The contest popularity value of participant i challenging participant j is A[j]-A[i]. The total contest popularity value of the competition is sum of popularity value of all such challenges.&lt;/p&gt;

&lt;p&gt;Given the energy of all participants, you have to find the total popularity value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INPUT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first line contains N, the number of participants. The next line contains N space separated integers representing the energy of all the participants.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OUTPUT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Print a single line containing the total popularity value.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;CONSTRAINTS&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
1&amp;lt;=N&amp;lt;=1000&lt;/p&gt;

&lt;p&gt;1 &amp;lt;=A[i]&amp;lt;= 1000000000&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXPLANATION OF SAMPLE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 Sample input has N as 7 and participants energy as 24 6 8 10 12 14. 2. The contest popularity based on rules described is as below:&lt;/p&gt;

&lt;p&gt;j-i                                     val diff&lt;/p&gt;

&lt;p&gt;5-0=5                              12-2=10&lt;/p&gt;

&lt;p&gt;3-0=3                              8-2 = 6&lt;/p&gt;

&lt;p&gt;2-0=2                              6-2 = 4&lt;/p&gt;

&lt;p&gt;6-1=5                              14-4 = 10&lt;/p&gt;

&lt;p&gt;4-1=3                              10-4 = 6&lt;/p&gt;

&lt;p&gt;3-1=2                               8-4 = 4&lt;/p&gt;

&lt;p&gt;5-2=3                              12-6 = 6&lt;/p&gt;

&lt;p&gt;4-2=2                              10-6 = 4&lt;/p&gt;

&lt;p&gt;6-3=3                              14-8= 6&lt;/p&gt;

&lt;p&gt;5-3=2                              12-8 = 4&lt;/p&gt;

&lt;p&gt;6-4=2                              14-10=4&lt;/p&gt;

&lt;p&gt;Total 64&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;7 2 4 6 8 10 12 14&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;64&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code(python 3)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def solution(n,A):

    sum=0

    for i in range(n):

        for j in range(n):

            if(j&amp;gt;i):

                num=j-i

                if(prime(num)):

                    sum=sum+(A[j]-A[i])

    return sum

def prime(n):

    if n==1:

        return False

    for i in range(2,int(n/2)+1):

        if n%i==0:

            return False

    return True

n=int(input())

A=list(map(int,input().split()))[:n]

print(solution(n,A))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More at : &lt;a href="https://onlylang.blogspot.com/"&gt;https://onlylang.blogspot.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Two Sum</title>
      <dc:creator>Shashi Vardhan</dc:creator>
      <pubDate>Thu, 03 Feb 2022 09:03:32 +0000</pubDate>
      <link>https://dev.to/notyetknown/two-sum-3fm6</link>
      <guid>https://dev.to/notyetknown/two-sum-3fm6</guid>
      <description>&lt;p&gt;Write a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The indices of these items should then be returned in a tuple like so: (index1, index2).&lt;/p&gt;

&lt;p&gt;For the purposes of this kata, some tests may have multiple answers; any valid solutions will be accepted.&lt;/p&gt;

&lt;p&gt;The input will always be valid (numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).&lt;/p&gt;

&lt;p&gt;Based on: &lt;a href="http://oj.leetcode.com/problems/two-sum/"&gt;http://oj.leetcode.com/problems/two-sum/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;twoSum [1, 2, 3] 4 === (0, 2)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code(Java Solution)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static int[] twoSum(int[] numbers, int target) {

         // TODO Auto-generated method stub

         int[] x = new int[2];

         for(int i=0;i&amp;lt;numbers.length;i++)

         {

              for(int j=0;j&amp;lt;numbers.length;j++)

              {

                  if(i!=j)

                  {

                       if(numbers[i]+numbers[j]==target)

                       {

                            x[0]=i;

                            x[1]=j;

                       }

                  }



              }

         }



        return x;

     }

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

&lt;/div&gt;



&lt;p&gt;More at : &lt;a href="https://onlylang.blogspot.com/"&gt;https://onlylang.blogspot.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>codewars</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
