We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/*
* Complete the 'stones' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER n
* 2. INTEGER a
* 3. INTEGER b
*/
public static List<Integer> stones(int n, int a, int b) {
Set<Integer> results = new TreeSet<>();
for (int i = 0; i < n; i++) {
int value = i * b + (n - 1 - i) * a;
results.add(value);
}
return new ArrayList<>(results);
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int T = Integer.parseInt(bufferedReader.readLine().trim());
for (int tItr = 0; tItr < T; tItr++) {
int n = Integer.parseInt(bufferedReader.readLine().trim());
int a = Integer.parseInt(bufferedReader.readLine().trim());
int b = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> result = Result.stones(n, a, b);
bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(Collectors.joining(" "))
+ "\n"
);
}
bufferedReader.close();
bufferedWriter.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Manasa and Stones
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.util.stream.*;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
}