Adobe Interview Question
Quality Assurance EngineersCountry: India
Interview Type: In-Person
I assume there are 2 questions underlying
1) String reversal - O(n) : Navigate from begin and end and swap values
2) Reverse order of Words - O(2*n) : 2 step process , reverse the entire string & then reverse the characters of the individual words (space is the delimeter) in step 1 itself keep track of indices which mark end of strings
char[] chars = new char[]{'a', 'b', 'c', 'd'};
int l = chars.length - 1;
int c = 0;
for(int i=0; i<=l/2;i++) {
char t = chars[l-i];
chars[l-i] = chars[i];
chars[i] = t;
c++;
}
System.out.println("Reversed String = " + new String(chars));
System.out.println("number of iterations = " + c);
What company is this for?
- puneet.sohi April 18, 2014Q3 is not possible to solve, you don't have any delimiters between the words.
Q1 and 2 can be solved in linear time.