• + 0 comments

    We know the output as follow:

    • if n=1 output stone will be (0)
    • if n=2 output stone will be (a, b)
    • if n=3 output stone will be (2a, a+b, 2b)
    • if n=4 output stone will be (3a, 2a+b, a+2b, 3b)
    • if n=5 output stone will be (4a, 3a+b, 2a+2b, a+3b, 4b) final output can be formulated as (n-i-1)*a + i*b ***where i ranges from 0 to n-1* **

    we can iterate over range 'n' and add these values to set remove duplicates.

    def stones(n, a, b):
        # Write your code here
        st = set()
        for i in range(n):
            num = (n-i-1)*b + i*a
            st.add(num)
    
        return sorted(st)