You are viewing a single comment's thread. Return to all comments →
Simple & intuitive approach:
vector<int> stones(int n, int a, int b) { vector<int> v; for(int i=0,j=n-1;i<n && j>=0;i++,j--){ int item=a*i+b*j; //finding a,b multiples with i&j v.push_back(item); } sort(v.begin(),v.end()); //Sorting auto it = unique(v.begin(), v.end()); //to Remove Duplicates v.resize(distance(v.begin(), it)); return v; }
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 →
Simple & intuitive approach: