## Recursive Voting - Facebook Top Interview Questions

You are given a list of integers votes representing election votes for candidates a and b. Each element in votes represents a vote to one of the two candidates: If votes[i] < 0, then it's a vote for a. If votes[i] ≥ n, then it's a vote for b. Otherwise, the vote at index i made the same vote as votes[votes[i]]. Return the number of votes that candidate a received. You can assume all votes are eventually made to either a or b. Constraints 0 ≤ n ≤ 100,000 where n is the len

View Solution →## Set Split - Facebook Top Interview Questions

Given a list of positive integers nums, return whether you can divide the list into two groups a and b such that: The sum of a and the sum of b are equal. Every number in a is strictly less than every number in b. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [4, 9, 5] Output True Explanation We can have a = [4, 5] and b = [9] and both of their sums are 9. Example 2 Input nums = [9, 9] Output False Explanati

View Solution →## Subtree with Maximum Value - Facebook Top Interview Questions

Given a binary tree root, return the maximum sum of a subtree. A subtree is defined to be some node in root including all of its descendants. A subtree sum is the sum of all the node values in the subtree. A subtree can be null in which case its sum is 0. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [3, [0, null, null], [2, [0, null, null], null]] Output 5

View Solution →## Tree Detection - Facebook Top Interview Questions

You are given two lists of integers left and right, both of them the same length and representing a directed graph. left[i] is the index of node i's left child and right[i] is the index of node i's right child. A null child is represented by -1. Return whether left and right represents a binary tree. Constraints n ≤ 100,000 where n is the length of left and right Example 1 Input left = [1, -1, 3, -1] right = [2, -1, -1, -1] Output True Example 2 Input

View Solution →## Intersecting Lines - Facebook Top Interview Questions

You are given a two-dimensional list of integers lines and integers lo and hi. Each element in lines contains [m, b] which represents the line y = mx + b. Return the number of lines that intersect with at least one other line between x = lo and x = hi, inclusive. Constraints 0 ≤ n ≤ 100,000 where n is the length of lines Example 1 Input lines = [ [2, 3], [-3, 5], [4, 6] ] lo = 0 hi = 1 Output 2 Explanation Lines [2, 3] and [-3, 5

View Solution →