## Task Run - Facebook Top Interview Questions

You are given a list of integers tasks where each different integer represents a different task type, and a non-negative integer k. Each task takes one unit of time to complete and each task must be done in order, but you must have k units of time between doing two tasks of the same type. At any time, you can be doing a task or waiting. Return the amount of time it takes to complete all the tasks. Constraints n ≤ 100,000 where n is the length of tasks Example 1 Input ta

View Solution →## Unobstructed Buildings - Facebook Top Interview Questions

You are given a list of integers heights representing building heights. A building heights[i] can see the ocean if every building on its right has shorter height. Return the building indices where you can see the ocean, in ascending order. Constraints 0 ≤ n ≤ 100,000 where n is the length of heights Example 1 Input heights = [1, 5, 5, 2, 3] Output [2, 4] Explanation We can see the ocean in building heights[2] and heights[4]. Example 2 Input heights

View Solution →## Binary Matrix Leftmost One - Facebook Top Interview Questions

You are given a two-dimensional list of integers matrix which contains 1s and 0s. Given that each row is sorted in ascending order with 0s coming before 1s, return the leftmost column index with the value of 1. If there's no row with a 1, return -1. Can you solve it faster than \mathcal{O}(nm)O(nm). Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 0, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1

View Solution →## Binary Search Tree Iterator Sequel - Facebook Top Interview Questions

Implement a binary search tree iterator with the following methods: next returns the next smallest element in the tree hasnext returns whether there is a next element in the iterator prev returns the next bigger element in the tree hasprev returns whether there is a previous element in the iterator For example, given the following tree root 4 / \ 2 7 / 5 Then we have it = BSTIterator(root) it.next() == 2 it.next() == 4 it.hasnext() == True i

View Solution →## Common Reachable Node - Facebook Top Interview Questions

You are given a two-dimensional list of integers edges representing a directed graph and integers a and b. Each element in edges contains [u, v] meaning there's an edge from u to v. Return whether there's some node c such that we can go from c to a and c to b. Constraints 1 ≤ n ≤ 100,000 where n is the length of edges Example 1 Input edges = [ [0, 4], [4, 3], [1, 2], [0, 1], [0, 2], [1, 1] ] a = 2 b = 3 Output True

View Solution →