Minimum elements to be added in a range so that count of elements is divisible by K | Javascript implementation of the approach ; Total elements in the range ; If total elements are already divisible by k ; Value that must be added to count in order to make it divisible by k ; Driver code
function minimumMoves ( k , l , r ) { let count = r - l + 1 ; if ( count % k == 0 ) return 0 ; return ( k - ( count % k ) ) ; } let k = 3 , l = 10 , r = 10 ; document . write ( minimumMoves ( k , l , r ) ) ;