if res remains INT_MAX , it means there are no characters that repeat only once or the string is empty
if ( res == INT_MAX ) return -1 ; else return res ; } int main ( ) { string str ; str = " geeksforgeeks " ; int firstIndex = firstNonRepeating ( str ) ; if ( firstIndex == -1 ) cout << " Either ▁ all ▁ characters ▁ are ▁ repeating ▁ or ▁ string ▁ is ▁ empty " ; else cout << " First ▁ non - repeating ▁ character ▁ is ▁ " << str [ firstIndex ] ; return 0 ; }