The Faulty Sensor interview question involves two arrays representing data from two sensors. One of the sensors is faulty. The fault occurs at exactly one index i: the sensor drops the value at i and then records all subsequent values shifted by one position. The last value recorded by the faulty sensor is then filled by an arbitrary value (or ignored). You need to determine which sensor is faulty (1, 2, or both/unknown).
Meta asks this Array interview pattern to test your attention to detail and ability to identify shifts in linear data. It's an "Easy" difficulty problem that evaluates whether you can handle index comparisons and find the point of divergence between two sequences. It requires a clean implementation of "what if" logic.
This problem uses a Two Pointers / Linear Scan approach.
i where sensor1[i] != sensor2[i].sensor1 from i should match sensor2 from i+1.sensor2 from i should match sensor1 from i+1.Sensor 1: [2, 3, 4, 5], Sensor 2: [2, 4, 5, 6]
2 == 2.3 != 4. Point of divergence is 1.sensor1[1] should match sensor2[2]? 3 vs 5. No.sensor2[1..2] ([4, 5]) matches sensor1[2..3] ([4, 5])? Yes.
Result: Sensor 2 is faulty.sensor1[i] with sensor2[i] instead of i+1).Whenever you need to check if one array is a "shifted" version of another, focus on the first point of difference. Once found, the relationship for the remainder of the arrays is fixed.