META | E4 | Mock interview

921
Jan 10, 2024

Hey guys! Just giving back to the community. I had my mock screen interview this morning and these were the questions. Just want to mention a few things before I put the questions. No surprises, everything is from most discussed facebook questions. I solved both of them quite easily and had a casual conversation with interviewer.

Couple things I understood from the interview -

  1. I need to somehow train myself to be in the same mental state as I would be when I am prepping.
  2. I was too worried about me not being able to solve the question if I haven't seen it before. Any tips here would be greatly appreciated.
  3. Coding the solution is great, but having a way of working through things is really beneficial and a plus point is what the interviewer said. What that means is, when you get a question, ask questions as they purposely give the input to be a bit confusing. Somethings you might think are obvious are not really obvious and the interviewer is expecting you to communicate those.

Here are the questions :

Q1

Question Statement

Given an array of integers (0 to 9) rearrange the positions of the array elements to represent a number which is the second largest possible.

Ex.

Input = [1,2,3,4,5]

Output = [5,4,3,1,2]

Largest number: [5,4,3,2,1] e.g. "54,321"

The second largest - Answer: [5,4,3,1,2] e.g. "54,312"

Q2

Question:

Given a binary tree root node, write a function that returns the tree diameter (represented by this node).

Definition: diameter of a tree is the number of nodes on the longest path between any two nodes.

Example:

1

/ \

2 3

/ / \

4 5 6

\

7

Longest path is between node #4 and node #7, and we have 4 nodes on that path (#2, #1, #3, #6) - therefore tree diameter is 2 + 4 = 6.

Comments (3)