Find the largest possible value of K such that K modulo X is Y | Function to find the largest positive integer K such that K % x = y ; Stores the minimum solution ; Return the maximum possible value ; Driver Code
function findMaxSoln ( n , x , y ) { var ans = - 1000000000 ; for ( var k = 0 ; k <= n ; k ++ ) { if ( k % x == y ) { ans = Math . max ( ans , k ) ; } } return ( ( ans >= 0 && ans <= n ) ? ans : - 1 ) ; } var n = 15 , x = 10 , y = 5 ; document . write ( findMaxSoln ( n , x , y ) ) ;