# 53. 连续字母长度
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let lines = [];
rl.on('line', function(line) {
lines.push(line);
if (lines.length === 2) {
let k = parseInt(lines[1]);
let str = lines[0];
let obj = {};
let s = str[0];
let count = 1;
for(let i=1; i<str.length; i++) {
if (str[i] === str[i-1]) {
count++;
} else {
obj[str[i-1]] = Math.max((obj[str[i-1]] || 0), count);
s = str[i];
count = 1;
}
}
let ans = [];
for(let i in obj) {
ans.push({n: i, v: obj[i]});
}
ans.sort((a,b) => b.v - a.v);
console.log(ans[k - 1] ? ans[k - 1].v : -1);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
← 52. 字符串分割转换 54. 火星文计算 →