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.
vector stones(int n, int a, int b) {
if (n <= 1) {
return {0};
}
set<int> current;
for (int i = 0; i < n; i++) {
int value = i * a + (n - 1 - i)*b; // i times a and (n-1-i) times b
current.insert(value);
}
vector<int> result(current.begin(), current.end());
return result;
}
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 →
C++ ans
vector stones(int n, int a, int b) { if (n <= 1) { return {0}; }
}