I recently interviewed with Graviton Research Capital for the Software Engineer role. The first round consisted of two problem-solving questions focusing on data structures and graph theory. The interview lasted around 60 minutes.
A sender transmits packets to a receiver.
P and P + 10 will never be reordered).You need to design a Receiver class with a function:
receive(packet_number)
that processes arriving packets and commits packets whenever possible.
Track the next expected packet number (next_commit).
Maintain a data structure storing received but uncommitted packets (a set or boolean array).
When a packet arrives:
next_commit, we attempt to commit packets sequentially.Continue committing while the next expected packet exists in the received set.
Because the problem guarantees at most 10 packets can be missing, the buffer size remains small and operations stay efficient.
Time complexity per packet: O(1) amortized.
Given:
N nodesM undirected edgesFind:
To maximize components, we should concentrate edges within a small subset of nodes while leaving the rest isolated.
Let X be the number of nodes used to place the edges.
A component of size X can contain at most:
X(X-1)/2 edges
We find the largest X such that
X(X-1)/2 ≤ M
Then:
X nodesMaximum components:
N - X + 1
To minimize components, we should use edges to connect as many nodes as possible.
Each edge can reduce components by at most 1.
Starting with N isolated nodes:
Minimum components:
max(1, N - M)
Explanation: