You are viewing a single comment's thread. Return to all comments →
cpp solution:
vector<int> stones(int n, int a, int b) { vector<int> retVal; if (a == b) { retVal.push_back(a * (n-1)); return retVal; } map<int, int> mappy; for (int i = 0; i < n; i++) { auto val = i * a + (n - 1 -i) * b; mappy.insert(make_pair(val, i)); } for (auto key : mappy) { retVal.push_back(key.first); } return retVal; }
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 →
cpp solution: