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.
public static List<Integer> stones(int n, int a, int b) {
int A = Math.min(a, b);
int B = a + b - A;
int val = A * (n - 1);
// An - A - Ai + Bi -> A(n - 1) - i(A - B)
return IntStream.range(0, n)
.map(i -> val - (i * (A - B)))
.distinct()
.boxed()
.collect(Collectors.toList());
}
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 →