Sort by

recency

|

950 Discussions

|

  • + 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;
    
  • + 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
    def stones(n, a, b):
        # Write your code here
        x = [ sum(i) for i in combinations_with_replacement([a,b], n -1 )]
            
        return sorted(set(x))
    
  • + 0 comments
     public static List<Integer> stones(int n, int a, int b) {
        // Write your code here
        int bigger = (a >= b) ? a : b;
        int smaller = (a <= b) ? a : b;
        int diff = bigger - smaller;
        int min = smaller * (n - 1);
        int current = min;
        List<Integer> lastValues = new ArrayList<Integer>();
        
        if(diff == 0) {
          lastValues.add(current);
          return lastValues;
        }
        
        for(int i = 0; i < n; i++) {
          //System.out.println(current);
          lastValues.add(current);
          current += diff;
          
    
    }
    
    return lastValues;
    
    }
    
  • + 0 comments

    I think there is something wrong with the examples except for the first one. The first parameter represents non-zero stone. However, in the rest example, including the test cases, n represents total number of stones including non-zero. This is the solution to pass all of the tests.

    public static List<int> Run(int count, int diff1, int diff2)
    {
    	if (diff1 == diff2) return [diff1 * (count - 1)];
    
    	var small = diff1 < diff2 ? diff1 : diff2;
    	var large = diff1 < diff2 ? diff2 : diff1;
    
    	var start = small * (count - 1);
    	var end = large * (count - 1);
    	var step = large - small;
    
    	if (start == 0) start += step;
    
    	var faces = new List<int>();
    
    	for (var i = start; i <= end; i += step)
    	{
    		faces.Add(i);
    	}
    
    	return faces;
    }