Modify array by removing ( arr [ i ] + arr [ i + 1 ] ) th element exactly K times | Function to modify array by removing every K - th element from the array ; Check if current element is the k - th element ; Stores the elements after removing every kth element ; Append the current element if it is not k - th element ; Return the new array after removing every k - th element ; Function to print the array ; Traverse the array l [ ] ; Function to print the array after performing the given operations exactly k times ; Store first N natural numbers ; Iterate over the range [ 0 , k - 1 ] ; Store sums of the two consecutive terms ; Remove every p - th element from the array ; Increment x by 1 for the next iteration ; Print the resultant array ; Given arrays ; Function Call
def removeEveryKth ( l , k ) : NEW_LINE INDENT for i in range ( 0 , len ( l ) ) : NEW_LINE INDENT if i % k == 0 : NEW_LINE INDENT l [ i ] = 0 NEW_LINE DEDENT DEDENT arr = [ 0 ] NEW_LINE for i in range ( 1 , len ( l ) ) : NEW_LINE INDENT if l [ i ] != 0 : NEW_LINE INDENT arr . append ( l [ i ] ) NEW_LINE DEDENT DEDENT return arr NEW_LINE DEDENT def printArray ( l ) : NEW_LINE INDENT for i in range ( 1 , len ( l ) ) : NEW_LINE INDENT print ( l [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT def printSequence ( n , k ) : NEW_LINE INDENT l = [ int ( i ) for i in range ( 0 , n + 1 ) ] NEW_LINE x = 1 NEW_LINE for i in range ( 0 , k ) : NEW_LINE INDENT p = l [ x ] + l [ x + 1 ] NEW_LINE l = removeEveryKth ( l , p ) NEW_LINE x += 1 NEW_LINE DEDENT printArray ( l ) NEW_LINE DEDENT N = 8 NEW_LINE K = 2 NEW_LINE printSequence ( N , K ) NEW_LINE