This function assumes that arr [ ] is sorted in increasing order according the first ( or smaller ) values in pairs .
function maxChainLength ( arr , n ) { let i , j , max = 0 ; let mcl = new Array ( n ) ;