## 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

## 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

## 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

## Next Permutation From Pool - Facebook Top Interview Questions

You are given two strings digits and lower both representing decimal numbers. Given that you can rearrange digits in any order, return the smallest number that's larger than lower. You can assume there is a solution. Constraints 1 ≤ n ≤ 100,000 where n is the length of digits 1 ≤ m ≤ 100,000 where m is the length of lower Example 1 Input digits = "852" lower = "100" Output "258" Example 2 Input digits = "090" lower = "0" Output "9" Explanation