SDE
Interview Date
05-09-2026
Result
Rejected
Difficulty
Medium
Rounds
01
Drive Type
Off-Campus
Topics asked
Detailed experience
The interviewer opened with an advanced linear recurrence challenge: "You are given a linear recurrence of order k defined by a_n = c_1 * a_{n-1} + c_2 * a_{n-2} + ... + c_k * a_{n-k} with known base cases a_0, ..., a_{k-1}; compute the n-th term a_n modulo 998244353 where n is up to 10^18 and k is up to 5000." I pointed out that standard matrix exponentiation constructs a k x k transition matrix and computes M^n in O(k^3 log n) time, which fails completely when k = 5000 because k^3 requires 1.25 * 10^11 operations per matrix multiplication. I proposed the Bostan-Mori Algorithm (or the Fiduccia / Berlekamp-Massey polynomial reduction via the Cayley-Hamilton theorem). The interviewer followed up: "Explain how Cayley-Hamilton collapses matrix exponentiation into polynomial multiplication, and how Bostan-Mori computes the single n-th coefficient in O(k log k log n) time." I explained that the generating function of the recurrence can be expressed in rational form as P(x) / Q(x), where deg(P) < k and deg(Q) = k, with Q(0) = 1. The n-th term corresponds to the coefficient [x^n] of P(x) / Q(x). To divide-and-conquer on n, we multiply the numerator and denominator by Q(-x): P(x)/Q(x) = (P(x) * Q(-x)) / (Q(x) * Q(-x)). Notice that the denominator Q(x) * Q(-x) is an even polynomial containing only even powers of x, which can be re-indexed as Q_new(x^2). Depending on whether n is even or odd, we extract only the even or odd degree coefficients from the transformed numerator polynomial P(x) * Q(-x), effectively halving the exponent n at each step while maintaining polynomial degrees bounded by 2k. Multiplying these polynomials using Number Theoretic Transform (NTT) takes O(k log k) per step, reducing n to 0 across log n steps for a total runtime of O(k log k log n) and O(k) memory. He then shifted to a computational geometry and discrete-point enumeration problem: "Given an arbitrary simple polygon with n integer lattice vertices (coordinates up to 10^9), compute the exact number of strictly interior integer grid points and the number of boundary integer grid points." I noted that ray-casting or point-in-polygon tests over a discrete bounding box would require checking up to 10^18 points, which is impossible. I pitched combining the Shoelace Formula with Pick's Theorem and the Greatest Common Divisor (GCD). The interviewer cut in: "Walk me through how GCD calculates boundary lattice points along an arbitrary segment, and how Pick's Theorem algebraically rearranges to yield the interior count." I broke down the two stages: first, for any line segment connecting two integer points (x1, y1) and (x2, y2), the number of integer points lying strictly on the segment (excluding the start point) is exactly gcd(|x2 - x1|, |y2 - y1|). Summing this GCD over all n directed perimeter edges of the polygon gives the exact total count of boundary points B in O(n log(max_coord)) time. Second, we compute the exact twice-area 2 * A of the polygon using the Shoelace Formula (cross product sum) using 128-bit integers to prevent coordinate overflow. Pick's Theorem states that Area = I + B / 2 - 1, where I is the number of strictly interior lattice points. Multiplying through gives 2 * Area = 2 * I + B - 2, which rearranges directly to I = (2 * Area - B + 2) / 2. This completely eliminates any coordinate search or spatial indexing, resolving the exact interior point count in O(n log(max_coord)) time and O(1) auxiliary space. For the final challenge, he introduced a dynamic graph algorithm on online connectivity: "Design a data structure for an undirected unweighted graph of n vertices that supports two online operations: insert an edge (u, v) and report whether the current girth of the graph (the length of the shortest cycle) is strictly less than 2k, or update the shortest cycle length dynamically." I pointed out that finding cycles naively requires re-running BFS from every node in O(V * (V + E)) after every single edge insertion, which is far too slow for an online stream. I proposed maintaining an online BFS with Bounded-Depth Neighborhood Search and Girth Pruning. The interviewer challenged me: "When a new edge (u, v) is added, why does the shortest cycle only need to be checked relative to (u, v), and how does depth-bounding by k keep the search sub-linear?" I explained that inserting an edge (u, v) can only create a new shortest cycle if that specific edge forms part of the cycle. Therefore, the length of the shortest new cycle formed through (u, v) is exactly 1 + dist(u, v) in the graph prior to inserting the edge. If the current global minimum girth is G, we only care if 1 + dist(u, v) < G. This means we only need to perform a bidirectional BFS between u and v searching up to depth floor((G - 1) / 2). If the two search frontiers do not meet within depth floor((G - 1) / 2), dist(u, v) >= G - 1, meaning no smaller cycle can possibly be formed. If the frontiers meet at distance d < G - 1, we update G = d + 1 and contract our search radius for all subsequent queries. Because the girth can only decrease and is bounded between 3 and 2k, the depth-bounded frontier search skips vast subtrees, keeping the average query time sub-linear. He verified the bidirectional termination conditions, confirming the dynamic model.