Minimum days required to cure N persons | Function to find minimum count of days required to give a cure such that the high risk person and risk person does not get a dose on same day . ; Stores count of persons whose age is less than or equal to 10 and greater than or equal to 60. ; Stores the count of persons whose age is in the range [ 11 , 59 ] ; Traverse the array arr ; If age less than or equal to 10 or greater than or equal to 60 ; Update risk ; Update normal_risk ; Calculate days to cure risk and normal_risk persons ; Print the days ; Given array ; Size of the array ; Given P
function daysToCure ( arr , N , P ) { var risk = 0 ; var normal_risk = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 60 arr [ i ] <= 10 ) { risk ++ ; } else { normal_risk ++ ; } } var days = parseInt ( ( risk / P ) + ( normal_risk / P ) ) ; if ( risk % P > 0 ) { days ++ ; } if ( normal_risk % P > 0 ) { days ++ ; } document . write ( days ) ; } var arr = [ 9 , 80 , 27 , 72 , 79 ] ; var N = arr . length ; var P = 2 ; daysToCure ( arr , N , P ) ;