<?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: Darshan V ( Darshan Animus )</title>
    <description>The latest articles on DEV Community by Darshan V ( Darshan Animus ) (@darshananimus).</description>
    <link>https://dev.to/darshananimus</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%2F758503%2F84a0913f-c3a9-460a-97e0-007a6be31273.jpeg</url>
      <title>DEV Community: Darshan V ( Darshan Animus )</title>
      <link>https://dev.to/darshananimus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darshananimus"/>
    <language>en</language>
    <item>
      <title>Josephus Problem | Iterative Solution | Java</title>
      <dc:creator>Darshan V ( Darshan Animus )</dc:creator>
      <pubDate>Fri, 25 Mar 2022 01:30:12 +0000</pubDate>
      <link>https://dev.to/darshananimus/josephus-problem-iterative-solution-java-284j</link>
      <guid>https://dev.to/darshananimus/josephus-problem-iterative-solution-java-284j</guid>
      <description>&lt;p&gt;&lt;strong&gt;History&lt;/strong&gt;&lt;br&gt;
Josephus Problem is theoretical game named after flavius Josephus, he  was historian, who was trapped along with his 40 soldiers in cave. Instead of surrendering to roman soldiers they choose to commit to suicide by drawing lots. Josephus states, by the grace of god or by luck, they were the only two to remain alive and surrender to roman soldiers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;br&gt;
There are 'n' number of people standing in a row waiting to be executed and only one remains alive. The problem has two values, one is the number of people and other is the way they are executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&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;
Input : N = 5, K = 2
Output : 3
Firstly, the Person at position 2 is out, 
then position 0 goes out, then position 4
Finally, the Person at position 1 is out. 
So the Person at position 3 survives.

Input : 7 4
Output : 2

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;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;Time Complexity: theta(2^n)
Space Complexity: theta(1)

import java.util.Scanner;
import java.util.Arrays;

public class Jos {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int temp = n;
        int count = 0;
        boolean[] arr = new boolean[n];
        Arrays.fill(arr, true);
        for (int i = 0; i &amp;lt; temp; i++) {
            if (n != 1) {
                if (arr[i])
                    count++;
                if (count == k) {
                    arr[i] = false;
                    count = 0;
                    n -= 1;
                }
                if (i == temp - 1) {
                    i = -1;
                }

            } else {
                break;
            }
        }
        for (int j = 0; j &amp;lt; arr.length; j++) {
            if (arr[j])
                System.out.println(j);
        }
    }
}

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

&lt;/div&gt;



</description>
      <category>java</category>
      <category>problemsolving</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>100days code challenge</title>
      <dc:creator>Darshan V ( Darshan Animus )</dc:creator>
      <pubDate>Mon, 21 Mar 2022 01:19:31 +0000</pubDate>
      <link>https://dev.to/darshananimus/100days-code-challenge-3o1p</link>
      <guid>https://dev.to/darshananimus/100days-code-challenge-3o1p</guid>
      <description>&lt;p&gt;*&lt;em&gt;Recursion&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Recursion is the process in which the function call itself until some condition(the condition is called the base case) is reached.&lt;/p&gt;
&lt;h2&gt;
  
  
  the key points in recursion are:-
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Recursive Function call.&lt;/li&gt;
&lt;li&gt;Base case.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Base case :-&lt;/strong&gt; it is stopping condition of the recursive call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;syntax :- &lt;code&gt;static int fact(int n)&lt;br&gt;
           {&lt;br&gt;
            if(n==0)&lt;br&gt;
                return 1&lt;br&gt;
             return n*fact(n-1)&lt;br&gt;
            }&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:- Palindrome check using Recursion&lt;/strong&gt;&lt;br&gt;
Palindrome is a number, which viewed from both sides is same.&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;

//Palindrome check with recursion
public class Palli {
    public int temp = 0;

    static int getReverse(int n, int temp) {
        if (n == 0)
            return temp;
        temp = temp * 10 + n % 10;
        return getReverse(n / 10, temp);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, temp = 0;
        System.out.println("Enter the Number");
        n = sc.nextInt();
        int cnum = getReverse(n, temp);
        System.out.println(cnum);
        if (n == cnum)
            System.out.println("The Number is a pallindrome");
        else
            System.out.println("The Number is not pallindrome");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 2:- Sum of Digits&lt;/strong&gt;&lt;br&gt;
The sum of digits is problem where a number is given and sum of each digit in the number must be calculated.&lt;br&gt;
ex: 253 = 2+5+3 = 10&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 SOD {
    static int soD(int n) {
        if (n == 0)
            return 0;
        return soD(n / 10) + n % 10;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(soD(n));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>day1</category>
      <category>100daysofcode</category>
      <category>java</category>
      <category>recursion</category>
    </item>
  </channel>
</rss>
