Skip to content

Commit

Permalink
manasa and stones
Browse files Browse the repository at this point in the history
  • Loading branch information
anushkasinghal11 committed Dec 23, 2020
1 parent 944c5da commit b638005
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Algorithms/Implementation/Manasa and Stones/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.io.*;
import java.util.*;

public class solution {

public static void main(String[] args) {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/
Scanner input = new Scanner(System.in);
int T = input.nextInt();

for (int i = 0; i < T; i++) {
int n = input.nextInt() - 1;// Minus 1 to account for 0 starting stone
int a = input.nextInt();
int b = input.nextInt();

// Edge case where no iterations are required
if (a == b) {
System.out.println(a * n + " ");
continue;
}

// make sure a is our min
if (a > b) {
int temp = a;
a = b;
b = temp;
}

int min = a * n;
int max = b * n;

// We only need to increment by difference because there are only two stones to
// choose from each time
for (int finalSteps = min; finalSteps <= max; finalSteps += (b - a)) {
System.out.print(finalSteps + " ");
}

System.out.println();

}
}
}

0 comments on commit b638005

Please sign in to comment.