Coding interview questions used at the giant tech companies

Empower11

Member
Joined
Aug 5, 2020
Messages
11
Reaction score
1
Level of tree with Maximum Sum

Given a binary tree, find the level in the tree where the sum of all nodes on that level is the greatest.

Here's an example and some starter code.

Code:
class Node:
  def __init__(self, value, left=None, right=None):
    self.value = value
    self.left = left
    self.right = right

  def __repr__(self):
    return f"(Value: {self.value} Left: {self.left} Right: {self.right})"


def tree_level_max_sum(root):
  # Fill this in.

n3 = Node(4, Node(3), Node(2))
n2 = Node(5, Node(4), Node(-1))
n1 = Node(1, n2, n3)

"""
    1          Level 0 - Sum: 1
   / \
  4   5        Level 1 - Sum: 9
 / \ / \
3  2 4 -1      Level 2 - Sum: 8

"""

print(tree_level_max_sum(n1))
# Should print 1 as level 1 has the highest level sum
 
Last edited:
My first question to any potential applicant. Do you have your own domain yet?
You mean potential company, would assume the first post is for a start-up.
Must be fun googling a random interview question to try and get people when they know nothing about your company and your company can't even afford a domain/own site.
 
Can I just say that this is a candidate for one of the worst most anticlimactic threads ever.
 
Go to interview.

Question asked:
Given a binary tree, find the level in the tree where the sum of all nodes on that level is the greatest.

Actual job:
You'll be responsible for adding all dropdown boxes onto the GUI.

And there you have it. Or they are looking for a senior C# developer. But you end up maintaining the Sharepoint environment
 
Go to interview.

Question asked:
Given a binary tree, find the level in the tree where the sum of all nodes on that level is the greatest.

Actual job:
You'll be responsible for adding all dropdown boxes onto the GUI.
In my experience:

Go to interview.

Question asked:
Given a binary tree, find the level in the tree where the sum of all nodes on that level is the greatest.

Answer:
This isn’t a real question, you should ask me about my 10 years of experience adding checkboxes instead.

On Actual job:
Combo boxes? I didn’t go to MIT goddamit!
 
Python:
def tree_level_max_sum(root): 
  lc = []
  def populate_lc(node, depth=0):
    if node == None:
      return
    if len(lc) < depth + 1:
      lc.append( 0 )
    lc[ depth ] = lc[ depth ] + node.value   
    populate_lc(node.left, depth + 1)
    populate_lc(node.right, depth + 1)

  populate_lc(root)
 
  return lc.index(max(lc))
 
I wonder if I just helped the OP do a take home interview test...

;)
 
And there you have it. Or they are looking for a senior C# developer. But you end up maintaining the Sharepoint environment

The actual job advert will say something like:

"Looking for full stack developer with over 10 years experience, must know C# .NET, PHP, Javascript, HTML, CSS, React, Angular, MSSQL, MongoDB, AWS + Docker + Kubernetes, Microsoft Office, Server and Database Administration, experience in Agile/Scrum software and project management lead role. Candidates with expert knowledge in <insert field or domain> preferred. Competitive market related salary.

And you end up maintaining the sharepoint environment.
 
Top
Sign up to the MyBroadband newsletter
X