1826. Faulty Sensor

202408230232
tags: #array

var badSensor = function(sensor1, sensor2) {
	for (let i = 0; i < sensor1.length - 1; i++) {
		if (sensor1[i] !== sensor2[i]) {
			if (sensor1[i] === sensor2[i + 1] && sensor2[i] !== sensor1[i + 1]) {
				return 1;
			}
			if (sensor2[i] === sensor1[i + 1] && sensor1[i] !== sensor2[i + 1]) {
				return 2;
			}
		}
	}
	return -1;
};

Reference

https://leetcode.com/problems/faulty-sensor/