Round 1
Questions:
-
The first problem was similar to this post: Amazon OA Question - Parentheses Perfection Kit.
Solution for the 1st problem:
public static long findMaxEfficiencyScore(String s, String kitParentheses, List<Integer> efficiencyRatings) { // Write your code here //open & close ratings score separate and sort desc //see already balanced or make balanced somehow using open & close //then try to achieve more score using open & close both at a time after balance. int n = efficiencyRatings.size(); List<Integer> open = new ArrayList<>(); List<Integer> close = new ArrayList<>(); for(int i = 0; i < kitParentheses.length(); i++) { if(kitParentheses.charAt(i) == '(') { open.add(efficiencyRatings.get(i)); } else { close.add(efficiencyRatings.get(i)); } } Collections.sort(open, Collections.reverseOrder()); Collections.sort(close, Collections.reverseOrder()); Stack<Character> stack = new Stack<>(); int closingBracket = 0; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == '(') { stack.push(s.charAt(i)); } else if(!stack.isEmpty()) { stack.pop(); } else { closingBracket++; } } int openBracket = stack.size(); long score = 0; int indexClose = 0; while(openBracket > 0) { score += close.get(indexClose++); openBracket--; } int indexOpen = 0; while(closingBracket > 0) { score += open.get(indexOpen++); closingBracket--; } while(indexOpen < open.size() && indexClose < close.size()) { score = Math.max(score, score + open.get(indexOpen) + close.get(indexClose)); indexOpen++; indexClose++; } return score; }
-
The second problem was exactly this one: Security Analysis Task - Two Passwords. Specific question not provided.
Candidate's Approach
For the first problem, the candidate implemented a solution that involved separating the efficiency ratings for open and close parentheses, sorting them, and then calculating the maximum efficiency score based on the balance of parentheses. The candidate was able to solve this problem optimally.
For the second problem, the candidate struggled to find a correct solution after several hours of thought and requested assistance or links to similar problems.
Interviewer's Feedback
No feedback provided.