Check if final remainder is present in original Array by reducing it based on given conditions | Python program to implement above approach ; copying original array ; loop till length of array become 2. ; find middle element ; pop element from front and rear ; find remainder ; append remainder to a ; now since length of array is 2 take product and divide it by n ; if remainder is present is original array return 1 , else return 0 ; calling function Reduced ; if x = 1 print YES else NO
def Reduced ( a , n ) : NEW_LINE INDENT original_array = a [ : ] NEW_LINE while len ( a ) != 2 : NEW_LINE INDENT mid = len ( a ) // 2 NEW_LINE mid_ele = a [ mid ] NEW_LINE start = a . pop ( 0 ) NEW_LINE end = a . pop ( ) NEW_LINE rmd = ( start * end ) % mid_ele NEW_LINE a . append ( rmd ) NEW_LINE DEDENT remainder = ( a [ 0 ] * a [ 1 ] ) % n NEW_LINE if remainder in original_array : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT Arr = [ 2 , 3 , 4 , 8 , 5 , 7 ] NEW_LINE N = len ( Arr ) NEW_LINE x = Reduced ( Arr , N ) NEW_LINE if x : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT