function isValidPassword2(n) {
let has2RepeatingDigits = false;
let repeatCount = 0;
let prevDigit = Infinity;
for (let digit of digitIterator(n)) {
if (digit > prevDigit) {
return false;
}
if (digit === prevDigit) {
repeatCount++;
} else {
if (repeatCount === 1) {
has2RepeatingDigits = true;
}
repeatCount = 0;
}
prevDigit = digit;
}
return repeatCount === 1 || has2RepeatingDigits;
}