Given a string which contains only letters. Sort it by lower case first and upper case second.
Have you met this question in a real interview?
Yes
Example
For "abAcD", a reasonable answer is "acbAD"
Note
It's not necessary to keep the original order of lower-case letters and upper case letters.
Challenge
Do it in one-pass and in-place.
public class Solution { /** *@param chars: The letter array you should sort by Case *@return: void */ public void sortLetters(char[] chars) { //write your code here if(chars == null || chars.length <=1) return; int start = 0 ; int end = chars.length -1; while(start < end){ while(start < end && isLowerCase(chars[start])){ start++; } while(start < end && !isLowerCase(chars[end])){ end--; } char temp = chars[start]; chars[start++] = chars[end]; chars[end--] = temp; } } public boolean isLowerCase(char x){ return x >= 'a' && x<= 'z'; } }