forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//Q->Fing Digits Given an integer, for each digit that makes up the integer | ||
// determine whether it is a divisor. Count the number of divisors occurring within the integer. | ||
|
||
import java.io.*; | ||
import java.math.*; | ||
import java.security.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
|
||
static int findDigits(int n) | ||
{ | ||
int t=n; | ||
int count=0; //initial ans | ||
while(t>0) | ||
{ | ||
int r=t%10; //exytracting the last digit | ||
if(r!=0){ | ||
if(n%r==0) //checking if it divides n | ||
count++; | ||
} | ||
t=t/10; //discarding the last digit | ||
} | ||
|
||
return count; //returning final ans | ||
|
||
|
||
} | ||
|
||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); | ||
|
||
int t = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
for (int tItr = 0; tItr < t; tItr++) { | ||
int n = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
int result = findDigits(n); | ||
|
||
bufferedWriter.write(String.valueOf(result)); | ||
bufferedWriter.newLine(); | ||
} | ||
|
||
bufferedWriter.close(); | ||
|
||
scanner.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//Q-->Sequence equation , algorithms(implementation) | ||
import java.io.*; | ||
import java.math.*; | ||
import java.security.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
|
||
static int[] permutationEquation(int[] p) { | ||
|
||
ArrayList<Integer> ll=new ArrayList<>(); //to store values | ||
for(int i = 0;i < p.length;i++) | ||
p[i]--; //decrementing p values by one according to indices | ||
|
||
// using double for loop we match for p(p(x))=y | ||
// first for x and second for y | ||
// as we have started from index 0, then we push index | ||
|
||
for(int i = 0; i < p.length; i++) { //for y | ||
for (int j = 0; j < p.length; j++) { //for x | ||
if (p[p[j]] == i) { | ||
ll.add(j+1); | ||
break; | ||
} | ||
} | ||
} | ||
int ans[]=new int[ll.size()]; //ans array to be returned | ||
for(int i=0;i<ans.length;i++){ | ||
ans[i]=ll.get(i); | ||
} | ||
return ans; | ||
} | ||
|
||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); | ||
|
||
int n = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
int[] p = new int[n]; | ||
|
||
String[] pItems = scanner.nextLine().split(" "); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
for (int i = 0; i < n; i++) { | ||
int pItem = Integer.parseInt(pItems[i]); | ||
p[i] = pItem; | ||
} | ||
|
||
int[] result = permutationEquation(p); | ||
|
||
for (int i = 0; i < result.length; i++) { | ||
bufferedWriter.write(String.valueOf(result[i])); | ||
|
||
if (i != result.length - 1) { | ||
bufferedWriter.write("\n"); | ||
} | ||
} | ||
|
||
bufferedWriter.newLine(); | ||
|
||
bufferedWriter.close(); | ||
|
||
scanner.close(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//Q->Utopian Tree , Algorithms(implementation) | ||
|
||
import java.io.*; | ||
import java.math.*; | ||
import java.security.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
|
||
static int utopianTree(int n) { | ||
|
||
int r = 1; // starting period , initial height = 1 | ||
for (int i = 1; i <= n; i++) { | ||
|
||
// (period%2==0 )--> height + 1 | ||
// (period%2!=0) ----> height * 2; | ||
|
||
if (i % 2 == 0) | ||
r++; | ||
else | ||
r = r * 2; | ||
} | ||
return r; | ||
|
||
} | ||
|
||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); | ||
|
||
int t = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
for (int tItr = 0; tItr < t; tItr++) { | ||
int n = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
int result = utopianTree(n); | ||
|
||
bufferedWriter.write(String.valueOf(result)); | ||
bufferedWriter.newLine(); | ||
} | ||
|
||
bufferedWriter.close(); | ||
|
||
scanner.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters