-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistinctSubstrings.js
More file actions
44 lines (43 loc) · 927 Bytes
/
Copy pathDistinctSubstrings.js
File metadata and controls
44 lines (43 loc) · 927 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
function runProgram(input){
input=input.trim().split("\n")
let tc=+input[0]
let line=1
for(let i=0;i<tc;i++){
let N=+input[line++]
let arr=input[line++]
console.log(substr(N,arr));
}
}
function substr(N,arr){
const set= new Set()
for(let i=0;i<=N;i++){
for(let j=i+1;j<=N;j++){
set.add(arr.substring(i,j))
}
}
return set.size
}
if (process.env.USERNAME === "Chaithanya") {
runProgram(`2
5
abcde
3
aaa`);
} else {
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/, "");
read = read.replace(/\n$/, "");
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/, "");
runProgram(read);
process.exit(0);
});
}