Check if final remainder is present in original Array by reducing it based on given conditions | C # 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
using System ; using System . Collections . Generic ; class GFg { static int Reduced ( List < int > a , int n ) { List < int > original_array = new List < int > ( a ) ; while ( a . Count != 2 ) { int mid = a . Count / 2 ; int mid_ele = a [ mid ] ; int start = a [ 0 ] ; a . RemoveAt ( 0 ) ; int end = a [ a . Count - 1 ] ; a . RemoveAt ( a . Count - 1 ) ; int rmd = ( start * end ) % mid_ele ; a . Add ( rmd ) ; int remainder = ( a [ 0 ] * a [ 1 ] ) % n ; for ( int i = 0 ; i < original_array . Count ; i ++ ) { if ( original_array [ i ] == remainder ) { return 1 ; } } } return 0 ; } int x = Reduced ( Arr , N ) ; if ( x > 0 ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }