• + 0 comments

    My solution in C language :

    int* stones(int n, int a, int b, int* result_count)
    {
        int i = 0, c = (a <= b) ? a : b, d = abs(a - b), t = (a != b) ? n : 1;
        
        int * answer = malloc(t * sizeof(int));
            
        *(answer+0) = 0 + c * (n-1);
            
        for (i = 1; i < t; ++i)
            *(answer+i) = *(answer+i-1) + d;
        
        *result_count = t;
            
        return answer;
    }
    

    The solution here is to use the absolute difference between the two differences to increment the initial value (0 + (smallest_value_between_a_and_b * (n-1))) until you reach the expected number of stones (initial value is the first stone).