Similar to https://leetcode.com/problems/product-of-two-run-length-encoded-arrays/
Output should be int instead of encoded vector.
I took 20 mins for above question.
Remove duplicates from string, after removal remaining characters will slide in.
eg: "abbba" -> "aa" -> ""
"ab" -> ""
Solution: Was able to came up with below approach only.
`public static String compress(String input){
Stack stack = new Stack<>();
boolean doDelete = false;
char previous = 'a';
for(char c : input.toCharArray()){
if(previous != c && doDelete){
stack.pop();
doDelete = false;
}
if(!stack.isEmpty() && stack.peek() == c){
doDelete = true;
continue;
}
stack.push(c);
previous = c;
}
if(doDelete)
stack.pop();
StringBuilder sb = new StringBuilder();
for(char c : stack)
sb.append(c);
return sb.toString();
}`
Key points
Time management - 5 (Intro) + { 2 * {5 (question + approach) + 5 (code) + 5 (dry run + edge cases)}} + 5 (QnA) ~ 40 mins.
Ofcourse 5 min is buffer as things might not go as planned.
Got confirmation from recruiter within a day that I can proceed to onsite.