title-img


Arithmetic Sequence Queries ☃️ - Google Top Interview Questions

You are given a list of integers nums and a two-dimensional list of integers queries. Each element in queries contains [i, j] and asks whether the sublist of nums from [i, j], inclusive, is an arithmetic sequence. Return the number of queries that are true. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums 0 ≤ m ≤ 100,000 where m is the length of queries Example 1 Input nums = [1, 3, 5, 7, 6, 5, 4, 1] queries = [ [0, 3], [3, 4], [2, 4] ]

View Solution →

Ascending Cards - Google Top Interview Questions

You are given a list of integers cards, and are looking to order the cards in a way so that they are revealed in ascending order. The cards are revealed in this manner: the top card is removed and revealed and then next card is moved to the back. This is repeated until there's no more cards. Return an ordering of the cards such that they are revealed in ascending order. Constraints n ≤ 100,000 where n is the length of cards Example 1 Input cards = [1, 2, 3, 4, 5] Output

View Solution →

Back to Front Linked List - Google Top Interview Questions

Given a singly linked list node, reorder it such that we take: the last node, and then the first node, and then the second last node, and then the second node, etc. Can you do it in \mathcal{O}(1)O(1) space? Constraints 0 ≤ n ≤ 100,000 where n is the number of nodes in node Example 1 Input node = [0, 1, 2, 3] Output [3, 0, 2, 1]

View Solution →

Ball Moves - Google Top Interview Questions

You are given a list of integers nums containing 0s and 1s where a 0 means the cell is empty and 1 means there's a ball there. Return a new list of integers A of the same length where A[i] is set to the total distance required to move all the balls to A[i]. The distance to move a ball in index j to index i is defined to be abs(j - i). Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 1, 0, 1] Output [4, 3, 4, 5] Explanation A[0] = abs(

View Solution →

Bipartite Graph - Google Top Interview Questions

Given an undirected graph represented as an adjacency list, return whether the graph is bipartite. Constraints n, m ≤ 250 where n and m are the number of rows and columns in graph Example 1 Input graph = [ [1], [0] ] Output True Explanation This is bipartite since the node 1 can belong in set A and node 2 can belong in set B. Then the edges 0 - > 1 and 1 -> 0 has one node in A and one node in B Example 2 Input Visualize graph = [ [2,

View Solution →