META | E5 | London | Screening | Jan'22
Anonymous User
1034
  1. Given array = [1,1,1,1,6,6,6,6,3,3,4,4]
  • How to present mentioned array efficiently in memory.
  • Compute dot product of two such vectors without expanding the input.

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.

  1. 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

  1. Keep a short and interesting introduction.
  2. You need to get an agreement on approach, complexity before starting code under 5 mins.
  3. Try to practice as much as possible and write code in 5 mins.
  4. Dry run on inputs and edge cases in 5 mins.
  5. Its ok to take a pause between questions to calm yourself, take a deep breath, sip of water and then focus.
  6. If stuck, request for hints politely. Its ok and better than pin drop silence.
  7. Show gratitude towards end :)

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.

Comments (3)