<?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: Jasraj Chouhan </title>
    <description>The latest articles on DEV Community by Jasraj Chouhan  (@isjasrajchouhan).</description>
    <link>https://dev.to/isjasrajchouhan</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%2F1473769%2Fbb1cbdab-8cc9-4bd6-a200-7492c4b177b2.jpeg</url>
      <title>DEV Community: Jasraj Chouhan </title>
      <link>https://dev.to/isjasrajchouhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/isjasrajchouhan"/>
    <language>en</language>
    <item>
      <title>Two sum problem solution in easy way [Day-03]</title>
      <dc:creator>Jasraj Chouhan </dc:creator>
      <pubDate>Thu, 09 May 2024 09:24:26 +0000</pubDate>
      <link>https://dev.to/isjasrajchouhan/two-sum-problem-solution-in-easy-way-day-03-a3o</link>
      <guid>https://dev.to/isjasrajchouhan/two-sum-problem-solution-in-easy-way-day-03-a3o</guid>
      <description>&lt;p&gt;Today is day 3 for our dsa series. Today we discussed about two sum problem which is very important to understand the use of hashmap and how to optimes the time complexity of solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;br&gt;
you give an array num of length n and a target value k. you find out all the no of pair which sum is equal to k.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
num = [1,2,3,-1,4] , n = 5 , k = 5&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
4&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Expiation *&lt;/em&gt;&lt;br&gt;
1 + 2 + 3 + (-1) = 5&lt;br&gt;
2 + 3 = 5&lt;br&gt;
1 + 4 = 5&lt;br&gt;
2 + (-1) + 4 = 5&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Brute Approch&lt;/strong&gt;&lt;br&gt;
we point the two pointer i , j at index 0 of array. and move in complete in array and find out pair which sum of (num[i] + num[j) is equal to target value k if yes then increase the counter;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&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;import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      System.out.println("Enter the size of an array");

      Scanner sc = new Scanner(System.in) ;

      int n = sc.nextInt();

      int a[] = new int[n] ;


      // 1,2,3,-1,4 


      // take the input from user for array's element
      for(int i = 0; i &amp;lt; n; i++) a[i] = sc.nextInt() ;

      System.out.println("Enter the value of k");
      int k = sc.nextInt() ;

      System.out.println("total no of pair is : " + totalPair(a , n , k));

  }


  public static int totalPair(int a[] , int n , int k) {
    int counter = 0;

    for(int i = 0; i &amp;lt; n ; i++) {
      for(int j = 0; j &amp;lt; n; j++) {
        if(a[i] + a[j] == k) counter++;
      }
    }

    return counter ;
  } 

}


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

&lt;/div&gt;



&lt;p&gt;Time complexity of above algorithm is O(N*N) or O(N^2) because we travel every time in loop for every iteration.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;If we optimes the above algorithm so we can use hashmap data structure which store the value and its frequency *&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we move in array then ele = a[i] we find out the a element which have value is (target - ele) in hashmap if yes then increase the counter ;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&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;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the size of the array");
        int n = sc.nextInt();

        int[] arr = new int[n];
        System.out.println("Enter the elements of the array");
        for (int i = 0; i &amp;lt; n; i++) {
            arr[i] = sc.nextInt();
        }

        System.out.println("Enter the value of k");
        int k = sc.nextInt();

        System.out.println("Total number of pairs is: " + totalPair(arr, k));
    }

    public static int totalPair(int[] arr, int k) {
        HashMap&amp;lt;Integer, Integer&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
        int count = 0;

        for (int num : arr) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        for (int num : arr) {
            int complement = k - num;
            if (map.containsKey(complement)) {
                count++;

            }
        }

        return count ;
    }
}

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

&lt;/div&gt;



&lt;p&gt;Time complexity is O(n) and space Complexity is also O(n) because we use extra space.&lt;/p&gt;

&lt;p&gt;if you any doubt related to this article please comment us. &lt;/p&gt;

</description>
      <category>dsa</category>
      <category>datastructures</category>
      <category>leetcode</category>
      <category>twosum</category>
    </item>
    <item>
      <title>swap the value of two variable Four method [Day-02]</title>
      <dc:creator>Jasraj Chouhan </dc:creator>
      <pubDate>Wed, 08 May 2024 22:28:54 +0000</pubDate>
      <link>https://dev.to/isjasrajchouhan/swap-the-value-of-two-variable-four-method-day-02-4cp8</link>
      <guid>https://dev.to/isjasrajchouhan/swap-the-value-of-two-variable-four-method-day-02-4cp8</guid>
      <description>&lt;p&gt;This is day 2 of learn DSA in this particular blog we learn about the how the swap the value of two variable.&lt;/p&gt;

&lt;p&gt;swap the value of two variable is important concept because many of sorting algrorithm used this conecpt for eg. Bubble Sort , Insertion Sort  and many algorithm.&lt;/p&gt;

&lt;p&gt;We discussed three to four method swap the value of two variable.&lt;/p&gt;

&lt;p&gt;input  : 2 4&lt;br&gt;
Output : 4 2&lt;br&gt;
input  : 5 0&lt;br&gt;
Output : 0 5&lt;/p&gt;

&lt;p&gt;Note : Second , third and fourth method is asked in many interviews so clearly understand these algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Method&lt;/strong&gt;&lt;br&gt;
Take four variable and store the value of 2 variable into 2 another variabel and print this . This is word method because we take extra space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import java.util.Scanner;

public class Second {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Enter any two numbers");
        int firstNum = sc.nextInt();
        int secondNum = sc.nextInt();

        int first = secondNum;
        int second = firstNum ;

        System.out.println("After swaping  " + first + " " + second);
        sc.close();


    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Second Method&lt;/strong&gt;&lt;br&gt;
use the third variable and swap the value .&lt;br&gt;
&lt;strong&gt;Approach&lt;/strong&gt; : &lt;br&gt;
take a third variable temp initially temp has null value or say nothing have a value . &lt;br&gt;
in first step give value of first variable to temp.&lt;br&gt;
in second step give value of first varibale to second num .&lt;br&gt;
in third step give value of second variable to temp variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Code
import java.util.Scanner;

public class Second {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Enter any two numbers");
        int firstNum = sc.nextInt();
        int secondNum = sc.nextInt();

        int temp ;
        temp = firstNum ;
        firstNum = secondNum ;
        secondNum = temp ;

        System.out.println("After swaping  " + firstNum + " " + secondNum);
        sc.close();


    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Third Method:&lt;/strong&gt;&lt;br&gt;
without using any third variable to swap the value of two variable.&lt;br&gt;
&lt;strong&gt;Approach&lt;/strong&gt;  : &lt;br&gt;
firstNum = fristNum + secondNum;&lt;br&gt;
secondNum = fristNum - secondNum ;&lt;br&gt;
firstNum = fristNum -  secondNum;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

public class Second {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Enter any two numbers");
        int firstNum = sc.nextInt();
        int secondNum = sc.nextInt();

        firstNum = firstNum + secondNum ;
        secondNum = firstNum - secondNum ;
        firstNum = firstNum - secondNum ;

        System.out.println("After swaping  " + firstNum + " " + secondNum);
        sc.close();


    }
}


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

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Fourth Method *&lt;/em&gt;&lt;br&gt;
This method is awsome it take less time to another method which we discussed above. we use the concept of bit manipulation.&lt;br&gt;
we take the xor(^) of two numbers.&lt;br&gt;
But first understand xor (^) operator&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
0 ^ 0 = 0&lt;br&gt;
1 ^ 1 = 0&lt;br&gt;
1 ^ 0 = 1&lt;br&gt;
0 ^ 1 = 1&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;xor(^) of two different value is always 1 but xor(^) of two same thing is 0&lt;/p&gt;

&lt;p&gt;Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

public class Second {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Enter any two numbers");
        int firstNum = sc.nextInt();
        int secondNum = sc.nextInt();

        firstNum = firstNum ^ secondNum ;
        secondNum = firstNum ^ secondNum ;
        firstNum = firstNum ^ secondNum ;

        System.out.println("After swaping  " + firstNum + " " + secondNum);
        sc.close();


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

&lt;/div&gt;



&lt;p&gt;if you have any doubt please tell us in comment I try to answer your question.&lt;/p&gt;

&lt;p&gt;if you not familiar with our dsa series please follow me .&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Print Digits of a number Beginners Coding Problem [Day-01]</title>
      <dc:creator>Jasraj Chouhan </dc:creator>
      <pubDate>Wed, 08 May 2024 07:50:50 +0000</pubDate>
      <link>https://dev.to/isjasrajchouhan/print-digits-of-a-number-beginners-coding-problem-day-01-448b</link>
      <guid>https://dev.to/isjasrajchouhan/print-digits-of-a-number-beginners-coding-problem-day-01-448b</guid>
      <description>&lt;p&gt;Hello dear my fellow friends today we discussed the how the print digits of a number in reaverse order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example or test cases
&lt;/h2&gt;

&lt;p&gt;input : 1234&lt;br&gt;
output : 4 3 2 1&lt;/p&gt;

&lt;p&gt;input : 2390 &lt;br&gt;
output : 0 9 3 2&lt;/p&gt;
&lt;h2&gt;
  
  
  Approch
&lt;/h2&gt;

&lt;p&gt;1.we take the modula of  the number by 10 then we get always last digit of a number.&lt;/p&gt;

&lt;p&gt;for example&lt;/p&gt;

&lt;p&gt;num = 123&lt;br&gt;
divide the num by 10 &lt;br&gt;
num % 10 = 3&lt;/p&gt;

&lt;p&gt;num = 4562&lt;br&gt;
num % 10 = 2&lt;/p&gt;

&lt;p&gt;it means we clear about this concept if we required last digit of number then we take the modula of number by 10 and get the last digit .&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In second we required next digit so we reduced the num by num/10&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;for example &lt;br&gt;
num = 123&lt;br&gt;
num % 10 = 3&lt;/p&gt;

&lt;p&gt;num = num / 10&lt;br&gt;
num = 123 / 10&lt;br&gt;
num = 12&lt;/p&gt;

&lt;p&gt;ok then our num is reduced from 123 to 12&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We repeat both the step until num is not zero.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ok let's move for coding section I used c, cpp, java and python language if you comming from another programming language so you can convert this code into your progamming language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;java&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;import java.util.Scanner;
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Enter a number");
        Scanner sc = new Scanner(System.in) ;
        int n = sc.nextInt();       //take input from user

        printDigits(n) ;        // call the printDigits function which print the all digits of a number in reverse order


    }

    public static void printDigits(int n) {

        while(n != 0) {
            System.out.print(n % 10 + " ");
            n /= 10;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;C&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;
#include &amp;lt;stdio.h&amp;gt;

void printDigits(int n) {
    while(n != 0) {
        printf("%d ", n % 10);
        n /= 10;
    }
}

int main() {
    printf("Enter a number: ");
    int n;
    scanf("%d", &amp;amp;n);

    printDigits(n);

    return 0;
}


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;cpp&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;#include &amp;lt;iostream&amp;gt;

void printDigits(int n) {
    while(n != 0) {
        std::cout &amp;lt;&amp;lt; n % 10 &amp;lt;&amp;lt; " ";
        n /= 10;
    }
}

int main() {
    std::cout &amp;lt;&amp;lt; "Enter a number: ";
    int n;
    std::cin &amp;gt;&amp;gt; n;

    printDigits(n);

    return 0;
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;python&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 print_digits(n):
    while n != 0:
        print(n % 10, end=" ")
        n //= 10

n = int(input("Enter a number: "))
print_digits(n)

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;javascript&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;function printDigits(n) {
    while (n !== 0) {
        process.stdout.write(n % 10 + " ");
        n = Math.floor(n / 10);
    }
}

console.log("Enter a number:");
let n = parseInt(prompt());
printDigits(n);

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

&lt;/div&gt;



&lt;p&gt;if you have any doubt related to this question please comment your doubt.&lt;/p&gt;

&lt;p&gt;if you are beggerner in coding please follow this series we covered complete dsa.&lt;/p&gt;

&lt;h1&gt;
  
  
  dsa #programming #daydsa Sure, here you go:
&lt;/h1&gt;

&lt;h1&gt;
  
  
  codingtips #programmerlife #techblog #learntocode #codegoals #codenewbie #algorithm #datastructures #pythonprogramming #javascript #webdevelopment #cplusplus #java #computerscience #developercommunity #codersofinstagram #codingisfun #programminghumor #codingbootcamp #codingjourney #codechef #hackerrank #codeforces #leetcode #interviewprep #softwareengineering #codingchallenge #100daysofcode #programmingquotes #codequality #debugging #codeart #codinglife #programmingmemes #womenintech #programminglanguage #codingproblems #codinginterview #frontenddevelopment #backenddevelopment #fullstackdeveloper #codebug #techcommunity #devlife #codingtutorial #codingislove #codingschool #programmingtips #opensource #programmingbooks #codingclub #codewars #programminglogic #codeaddict #codingworld #programmingthoughts #codingislife #programmerrepublic #codingforbeginners #codingwisdom #codingiscreativity #programmingeducation #codingisart #codingfromscratch #codingisawesome #programminglife #codingstudio #programming101 #codinginspiration #codered #codingmindset #programmingfun #codingisbeautiful #codingiscool #codingworld #codingtherapy #programmingjourney #codeyourfuture #codingexplained
&lt;/h1&gt;

</description>
      <category>dsa</category>
      <category>beginners</category>
      <category>simpleproblem</category>
      <category>printdigits</category>
    </item>
  </channel>
</rss>
