text: Check if sum Y can be obtained from the Array by the given operations | Function to check if it is possible to obtain sum Y from a sequence of sum X from the array arr [ ] ; Store the difference ; Iterate over the array ; If diff reduced to 0 ; Driver Code
code: function solve ( arr , n , X , Y ) { var diff = Y - X ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != 1 ) { diff = diff % ( arr [ i ] - 1 ) ; } } if ( diff == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 1 , 2 , 7 , 9 , 10 ] ; var n = arr . length ; var X = 11 , Y = 13 ; solve ( arr , n , X , Y ) ;