Google interview question

given a string write a function to return the index of the first elememt which is non-alphabat ordered

Interview Answers

Anonymous

12 Jun 2015

#Python #total running time = O(n) def search_nonAlphabet(s): s = s.lower() for i in range(len(s)-1): if s[i+1] < s[i]: #print(s[i], i) return i s = 'AbcHowAreYou' search_nonAlphabet(s)

1

Anonymous

13 Apr 2015

//C++ #include #include int indexOfFirstNonAlphaNumeric( const std::string& str ) { for( int i = 0; i 0 ) { if( tolower( str[i] ) < tolower( str[i - 1] ) { return i - 1; } else if( tolower( str[i] ) == tolower( str[i - 1] ) { if( str[ i ] < str[ i - 1 ] ) { return i - 1; } } } } return str.size( ); //agree on some value that means not found - like -1 or size of string }

Anonymous

30 Mar 2015

Can you please update about other interview rounds?

Anonymous

5 Apr 2015

int first_nonalphabetical(const char* str) { char max = 255; while (str) { } }

Anonymous

11 Apr 2015

public class IndexOfNonAlpha { public static int findIndex(String ip) { for(int i=0;i='a'&&c='A'&&c<='Z')) continue; else return i; } return -1; } public static void main(String[] args) { System.out.println(findIndex("glassDoor")); System.out.println(findIndex("glassDoor!!!!!!!")); } }