Friday, February 1, 2019

Find increment sequence

  • Problem Description

    Perform sorting on list of integers and print the sequence showing order of increment.
  • CODING ARENA
  • a=int(input())
    x=input().split()
    y=[]
    for i in range(a):
        y.append(int(x[i]))
    print("Sorted List:")
    y.sort()
    print(y)
    print("Sequence of increments:")
    z=[]
    for i in range(a-1):
        m=(y[i+1]-y[i])
        z.append(m)
    print(z)
  • Test Case 1

    Input (stdin)
    5
    
    11 24 77 66 55
    
    
    Expected Output
    Sorted List:
    
    [11, 24, 55, 66, 77]
    
    Sequence of increments:
    
    [13, 31, 11, 11]
  • Test Case 2

    Input (stdin)
    5
    
    2 2 2 2 2
    
    
    Expected Output
    Sorted List:
    
    [2, 2, 2, 2, 2]
    
    Sequence of increments:
    
    [0, 0, 0, 0]

No comments:

Post a Comment