编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
// console.log("Hello world!            -  js.jsrun.net ");
function fn(list = [], time) {
    let ret = 1
    for(let i = 0; i <= list.length - time; i++) {
        const map = {};
        for(let j = i; j < i + time; j++) {
            if (!map[list[j]]) map[list[j]] = 0
            map[list[j]]++
            if (map[list[j]] > ret) ret = map[list[j]]
        }
    }
    console.log(ret);
}

fn([0,1,2,1], 3)

fn([0,1,2,1], 2)