• + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/BXNoCVP0XEE Solution 1 :

    vector<int> stones(int n, int a, int b) {
        if(a > b){
            a = b + a;
            b = a - b;
            a = a - b;
        }
        int step = b - a;
        vector<int> result;
        for(int i = a * (n-1); i < b * (n-1); i += step) result.push_back(i);
        result.push_back(b * (n-1));
        return result;
    }
    

    Solution 2 :

    vector<int> stones(int n, int a, int b) {
        vector<int> result;
        for(int i = min(a, b) * (n-1); i < max(a,b) * (n-1); i += abs(b - a)) result.push_back(i);
        result.push_back(max(a, b) * (n-1));
        return result;
    }