Find the character in first string that is present at minimum index in second string | method to find the minimum index character ; to store the index of character having minimum index ; lengths of the two strings ; traverse ' patt ' ; for each character of ' patt ' traverse ' str ' ; if patt . charAt ( i ) is found in ' str ' , check if it has the minimum index or not . If yes , then update ' minIndex ' and break ; print the minimum index character ; if no character of ' patt ' is present in ' str ' ; Driver Method
function printMinIndexChar ( str , patt ) { let minIndex = Number . MAX_VALUE ; let m = str . length ; let n = patt . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( patt [ i ] == str [ j ] && j < minIndex ) { minIndex = j ; break ; } } } if ( minIndex != Number . MAX_VALUE ) document . write ( " " + str [ minIndex ] ) ; else document . write ( " " ) ; } let str = " " ; let patt = " " ; printMinIndexChar ( str , patt ) ;