Wish | Phone Screen | JSON to HTML String & Min Stack

Position: Front End Engineer
Date: September 2019
Result: Rejected

I was contacted by a recruiter and was scheduled for an hour long technical phone round.
Initially the engineer introduced himself and talked a little about his work. Then it was my turn and I explained what I do, and my tech stack.
After 15min we went on to the codepair link recruiter had shared.
The interviewer was nice to chat with but he did not seem involved in the interview, he went blank a couple of times - may be he was working.

Question 1:
Given a JSON object, write a function that converts it into a string.

Example:

Input:
const json = {
	value: "test"
}
Output: "<body>test</body>"

I asked if he meant to return dom elements from the string but he wanted string only. I wrote a recursive function solution that checked if json was object, array or string and create element accordingly, with the values - but he did not seem convinced. He kept on asking me to return a string that looked like above.

Question 2:
https://leetcode.com/problems/min-stack/

My solution

To this, my approach was to implement logic while pushing into the stack and readjust element in stack once we popped an item, so we can keep minimum element always on top. He did not seem convinced. Below is my solution:

class Stack {
  constructor() {
    this.items = [];
    this.minEl = 0;
  }

  push(item) {
    if (this.items.length === 0) {
      this.minEl = item;
      this.items.push(item);
      return;
    }
    if (item < this.minEl) {
      this.items.push(2 * item - this.minEl);
      this.minEl = item;
    } else {
      this.items.push(item);
    }
  }

  pop() {
    if(this.items.length === 0) {
      return;
    }
    
    let temp = this.items.pop(); 
    if(temp < this.minEl) {
      this.minEl = 2*this.minEl - temp; 
    } else {
      return temp;
    }
  }

  getMin() {
    return this.minEl;
  }
}

const stack = new Stack();

stack.push(4);
stack.push(5);
console.log(stack.getMin()); //4

stack.push(6);
stack.push(1);

console.log("round 2",stack.getMin());  // 1

None of the Leetcode Wish tagged questions were asked. Even though recruiter told me phone round was going to be all CS - the first question was more web dev related. I got a reject email in an hour.

Comments (3)