Interview questions
Find a company or topic. Read the sources, then practice.
Loading the question library…
Find a company or topic. Read the sources, then practice.
Loading the question library…
Showing 1,476–1,500
Given timestamped bike-usage records, determine each bike's most recent usage time (and optionally return bikes sorted by last-used). This requires aggregating logs and…
General practice
Find the maximum distance between consecutive 1 bits in the binary representation of n by locating the positions of 1s and returning the largest difference…
General practice
Determine whether the binary representation of a positive integer has alternating bits, i.e., every pair of adjacent bits differs. The task focuses on an efficient…
General practice
Given a binary array, return for each prefix whether the integer value of that binary prefix is divisible by 5. The key is to update…
General practice
Design a bidirectional in-order iterator for a binary search tree that lets you move forward and backward through the sorted elements via next()/hasNext() and prev()/hasPrev()…
General practice
Transform a BST so each node's value becomes its original value plus the sum of all keys greater than it; this is typically done with…
Companies: Apple
Binary Search Tree · Binary Tree · Depth-First Search · Tree
Given an unsorted array, count the elements that are "binary searchable" — values that would be found by standard binary search without sorting, meaning every…
Companies: Uber
Array · Binary Search · Monotonic Stack · Stack
Determine whether every integer from 1 to n has its binary representation appearing as a contiguous substring of s; since n can be much larger…
General practice
Count the number of non-empty contiguous subarrays in a binary array whose elements sum to a given goal — equivalently, count pairs of indices where…
General practice
Find the length of the longest path in a binary tree where adjacent node values differ by exactly 1 (either increasing or decreasing), and the…
General practice
Given a binary tree, compute the total number of nodes; while a straightforward DFS/BFS counts in O(n), the Medium variant typically requires exploiting tree structure…
General practice
Return the values of a binary tree in postorder (left → right → root). The recursive approach is trivial; the follow-up asks for an iterative…
General practice
Return the preorder (root–left–right) traversal of a binary tree as a list of node values. The recursive solution is trivial; the follow-up asks for an…
Companies: Meta
Binary Tree · Depth-First Search · Stack · Tree
Given a binary tree with node values 0 or 1, remove every subtree that does not contain a 1 and return the pruned tree. This…
General practice
Given unique integers >1 (n ≤ 1000), count binary trees (values may be reused) where every non-leaf node equals the product of its children; compute…
General practice
Return all valid times (H:MM) where the 4-bit hour (0–11) and 6-bit minute (0–59) representations have exactly turnedOn ones in total. This is a combinatorics/bit-counting…
General practice
Implement a custom bind that returns a new function with its this fixed to a given context and optional preset arguments. Ensure the bound function…
General practice
Return the bitwise AND of all integers in [left, right]; the result is simply the common high-order binary prefix of left and right since any…
General practice
Given an integer array, produce a new array of length n-1 where each element is the bitwise OR of consecutive elements from the original array…
General practice
Given an integer array, compute the bitwise OR of the sums of every possible subsequence. The challenge is to decide which bit positions can appear…
General practice
Filter the array for even numbers and compute their cumulative bitwise OR; return 0 if no even numbers exist. This is a straightforward O(n) linear-scan…
General practice
Given an array of integer bitmasks representing user permissions, analyze and answer queries like counting users with specific bits, detecting overlapping/conflicting…
General practice
Compute the bitwise XOR of all pairwise XORs nums1[i] ^ nums2[j] for every i, j; use XOR's associativity and cancellation so the result depends only…
General practice