Created
February 11, 2018 23:03
-
-
Save caglarorhan/2e8e8d7e6332afbd4e5c633cd336cae8 to your computer and use it in GitHub Desktop.
Sparse Arrays from https://www.hackerrank.com/challenges/sparse-arrays/problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processData(input) { | |
//Enter your code here | |
let rows = input.split("\n"); | |
let stringCount = parseInt(rows[0]); | |
let queryOccursCount=[]; | |
let queryCount=parseInt(rows[stringCount+1]); | |
//console.log("qc:"+ queryCount); | |
for(q=0;q<queryCount;q++){ | |
queryOccursCount.push(parseInt(0)); | |
for(xcv=0; xcv<stringCount; xcv++){ | |
//console.log(rows[xcv+1]+" : "+rows[parseInt(stringCount+2+q)]); | |
if(rows[xcv+1]==rows[parseInt(stringCount+1+q+1)]){queryOccursCount[q]++;} | |
} | |
} | |
//console.log(queryOccursCount); | |
queryOccursCount.forEach(function(i){ | |
console.log(i); | |
}); | |
} | |
process.stdin.resume(); | |
process.stdin.setEncoding("ascii"); | |
_input = ""; | |
process.stdin.on("data", function (input) { | |
_input += input; | |
}); | |
process.stdin.on("end", function () { | |
processData(_input); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a collection of strings ( There can be multiple occurences of a particular string ). Each string's length is no more than characters. There are also queries. For each query, you are given a string, and you need to find out how many times this string occurs in the given collection of strings.
Input Format
The first line contains , the number of strings.
The next lines each contain a string.
The nd line contains , the number of queries.
The following lines each contain a query string.
Constraints
Sample Input
4
aba
baba
aba
xzxb
3
aba
xzxb
ab
Sample Output
2
1
0
Explanation
Here, "aba" occurs twice, in the first and third string. The string "xzxb" occurs once in the fourth string, and "ab" does not occur at all.