Faulty Sensor - Problem
You're working as a quality assurance engineer for a high-tech laboratory where two identical sensors are used to collect critical experimental data simultaneously for redundancy and accuracy verification.
Each sensor produces an array of data points: sensor1[i] and sensor2[i] represent the i-th measurement from each sensor. However, these sensors have a known manufacturing defect that causes exactly one data point to be dropped during transmission.
When a data point is dropped:
- All subsequent data points shift left by one position
- The last position gets filled with a random value (guaranteed to be different from the dropped value)
- For example:
[1,2,3,4,5]with dropped value3becomes[1,2,4,5,7]
Your task: Determine which sensor (1 or 2) has the defect, or return -1 if it's impossible to determine or if both sensors are working correctly.
Input & Output
example_1.py โ Basic Case
$
Input:
sensor1 = [2,3,4,5], sensor2 = [2,1,3,4]
โบ
Output:
1
๐ก Note:
Sensor1 is faulty. If we remove the first element (2) from sensor1, we get [3,4,5]. But sensor2 without the last element is [2,1,3]. These don't match. However, if we consider that sensor1 dropped element 1 that should have been at position 1, sensor1 becomes [2,1,4,5] which matches sensor2's first 3 elements [2,1,3]. Wait, let me reconsider... Actually, if sensor1 dropped the value that should be at position 1, sensor1 originally was [2,1,3,4,5], and after dropping 1, it became [2,3,4,5]. Sensor2 shows [2,1,3,4], so sensor1 is missing the 1.
example_2.py โ Sensor2 Faulty
$
Input:
sensor1 = [2,1,3,4], sensor2 = [2,3,4,5]
โบ
Output:
2
๐ก Note:
Sensor2 is faulty. The original data should be [2,1,3,4,5]. Sensor2 dropped the element 1, causing [2,3,4,5] with the last element being a random value 5.
example_3.py โ No Defect Detectable
$
Input:
sensor1 = [1,2,3], sensor2 = [1,2,3]
โบ
Output:
-1
๐ก Note:
Both sensors show identical readings, so either both are working correctly or the defect cannot be determined from the given data.
Constraints
- 1 โค sensor1.length, sensor2.length โค 105
- 1 โค sensor1[i], sensor2[i] โค 109
- sensor1.length == sensor2.length
- At most one sensor has exactly one missing data point
Visualization
Tap to expand
Understanding the Visualization
1
Synchronize Playback
Start comparing both recordings frame by frame from the beginning
2
Detect Anomaly
Stop when you find the first frame that doesn't match between cameras
3
Test Hypotheses
Check if skipping one frame from either camera resolves all remaining differences
Key Takeaway
๐ฏ Key Insight: Once we find where the recordings diverge, we only need to test if one camera missed a single frame at that exact point
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code