JavaScript Interview Questions — Microsoft

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.

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

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

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.

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.

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

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

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store