Function to return the ending index for the largest valid sub - string starting from index i
function getEndingIndex ( str , n , i ) { i ++ ; while ( i < n ) { let curr = str [ i ] ; let prev = str [ i - 1 ] ;