if res remains Integer . MAX_VALUE , it means there are no characters that repeat only once or the string is empy
if ( res == Int32 . MaxValue ) return - 1 ; else return res ; } public static void Main ( ) { string str ; str = " geeksforgeeks " ; int firstIndex = firstNonRepeating ( str ) ; if ( firstIndex == - 1 ) Console . WriteLine ( " Either ▁ all ▁ characters ▁ are ▁ repeating ▁ or ▁ string ▁ is ▁ empty " ) ; else Console . WriteLine ( " First ▁ non - repeating ▁ character ▁ is ▁ " + str [ firstIndex ] ) ; } }