JavaScript Interview Questions — Microsoft

Gaurav Behere
2 min readAug 18, 2020

Questions from the recent interview experience

You are given the root of a binary tree & a reference node’s value. You have to list all the nodes that are below K levels from the reference node.

Sample 1

Input: Root Node Address (7), Reference Node Value: 6, K=1
Output: 4

Sample 2

Input: Root Node Address (7), Reference Node Value: 6, K=2
Output: 4, 5

Sample 3

Input: Root Node Address (7), Reference Node Value: 3, K=3
Output: 1, 6, 0, 2, 4, 5

Design a browser

This can be a tricky question if we don’t negotiate the scope well.
We need to discuss what all functionalities the interviewer is expecting.

We have to come up with high-level definitions of the classes that we will need.

Basic functionalities that you will have to design for:

  1. HTML rendering.
  2. JS execution.
  3. Fetching resources.
  4. Tokenization, creating a DOM tree.
  5. Multiple tabs.
  6. Resource caching.
  7. Managing history.

What is an event loop & how would you design one?

This video explains the event loop very well:

When it comes to designing an event loop you will have come up with class definitions for all the components of the event loop & explain how a task will move from one component to another.

Determine the output, the order in which console.logs will be executed.

You are given an array of stock prices over days. You have to determine what is the maximum profit one can make provided a single transaction can be done.

Sample

Input: [100, 180, 260, 310, 40, 535, 695]

Output: 644 (Buy on the day 4, sell on the day 6)

--

--

Gaurav Behere

Full-stack engineer, drummer, running on JS & Music. “Frameworks & Libraries come & go, JS stays ❤” https://www.linkedin.com/in/gauravbehere/