study/알고리즘 문제 풀이

[javaScript] Softter - 징검다리

dddzr 2024. 1. 11. 16:56

 

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let n;
let alist = [];

let count = 0;
rl.on('line', function(x){
    if(count == 0){
        n = Number(x);
    }else {
        alist = x.split(' ').map(Number);
        printCnt();
        rl.close();
    }   
    count++;
}).on('close', function(){
    
})

function printCnt(){
    let cnt = 1;
    for(let i = 1; i <= n; i++){
        let gap = Math.abs(alist[i]-alist[i-1]);
        if(gap < 2){
            cnt++;
        }else {
            console.log(cnt);
            break;
        }
    }
}