-
Notifications
You must be signed in to change notification settings - Fork 3
/
ManasaAndStones.java
35 lines (31 loc) · 1.09 KB
/
ManasaAndStones.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// https://www.hackerrank.com/challenges/manasa-and-stones/problem
package implimentation;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class ManasaAndStones {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int queries = scanner.nextInt();
while (queries-- > 0) {
int stones = scanner.nextInt();
int step1 = scanner.nextInt();
int step2 = scanner.nextInt();
printLastStonePossibilities(stones, step1, step2);
}
}
private static void printLastStonePossibilities(int stones, int a, int b) {
Set<Integer> visited = new HashSet<>();
int minStep = Math.min(a, b);
int maxStep = Math.max(a, b);
for (int index = 0 ; index < stones ; index++) {
int value = minStep * (stones - index - 1) + maxStep * index;
if (visited.contains(value)) {
continue;
}
visited.add(value);
System.out.print(value + " ");
}
System.out.println();
}
}