Find the character in first string that is present at minimum index in second string | Java implementation to 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
public class GFG { static void printMinIndexChar ( String str , String patt ) { int minIndex = Integer . MAX_VALUE ; int m = str . length ( ) ; int n = patt . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( patt . charAt ( i ) == str . charAt ( j ) && j < minIndex ) { minIndex = j ; break ; } } } if ( minIndex != Integer . MAX_VALUE ) System . out . println ( " Minimum ▁ Index ▁ Character ▁ = ▁ " + str . charAt ( minIndex ) ) ; else System . out . println ( " No ▁ character ▁ present " ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; String patt = " set " ; printMinIndexChar ( str , patt ) ; } }