unknown Interview Question
Software Engineer / DevelopersCountry: United States
public String lexicoGraphicallylly(String str) {
HashMap<Character, Integer> countChar = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
if (countChar.get(str.charAt(i)) == null) {
countChar.put(str.charAt(i), 1);
} else {
int count = countChar.get(str.charAt(i));
countChar.put(str.charAt(i), count + 1);
}
}
StringBuffer test = new StringBuffer();
char ch = 0;
// Get the least character from the string and its count..
for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
if (countChar.get(alphabet) != null) {
ch = alphabet;
break;
}
}
for (int i = 0; i < countChar.get(ch); i++) {
test.append(ch);
}
String test1 = str.replaceAll(Character.toString(ch), "");
return test.append(test1).toString();
}
public String lexicoGraphicallylly(String str) {
HashMap<Character, Integer> countChar = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
if (countChar.get(str.charAt(i)) == null) {
countChar.put(str.charAt(i), 1);
} else {
int count = countChar.get(str.charAt(i));
countChar.put(str.charAt(i), count + 1);
}
}
StringBuffer test = new StringBuffer();
char ch = 0;
// Get the least character from the string and its count..
for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
if (countChar.get(alphabet) != null) {
ch = alphabet;
break;
}
}
for (int i = 0; i < countChar.get(ch); i++) {
test.append(ch);
}
String test1 = str.replaceAll(Character.toString(ch), "");
return test.append(test1).toString();
}
public String lexicoGraphicallylly(String str) {
- Ashokkumar S.Angadi September 18, 2016HashMap<Character, Integer> countChar = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
if (countChar.get(str.charAt(i)) == null) {
countChar.put(str.charAt(i), 1);
} else {
int count = countChar.get(str.charAt(i));
countChar.put(str.charAt(i), count + 1);
}
}
StringBuffer test = new StringBuffer();
char ch = 0;
// Get the least character from the string and its count..
for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
if (countChar.get(alphabet) != null) {
ch = alphabet;
break;
}
}
for (int i = 0; i < countChar.get(ch); i++) {
test.append(ch);
}
String test1 = str.replaceAll(Character.toString(ch), "");
return test.append(test1).toString();
}