Sort by

recency

|

953 Discussions

|

  • + 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;
    } 
    
  • + 0 comments

    Here is PHP solution!

    n-1; b- current = (b) ? b; current * arr[] = $initial;

    for (i <i++) { arr); count-1; arr[diff; new; } arr);

  • + 0 comments

    Here is my Python solution!

    def stones(n, a, b):
        finals = []
        for first in range(n):
            finals.append(first * max(a, b) + (n - first - 1) * min(a, b))
        return sorted(list(set(finals)))
    
  • + 0 comments

    There's a mistake in multiple places in problem description (n should be the number of non-zero stones, but it's the number of all stones). Python3

        n -= 1
        solutions = set(a*i + b*(n-i) for i in range(n+1))
        return sorted(solutions)
    
  • + 0 comments
    int diff = abs(b-a);
        int ans = (n-1)*min(a,b);
        
        vector<int>result;
        result.push_back(ans);
        
        for(int i = 0; i< n-1;i++){
            if(result[i]+diff == result[i]) continue;
            result.push_back(result[i]+diff);  
        } 
        
        return  result;