일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Server
- Github
- CNN
- memory bank
- Anaconda
- 코딩테스트
- 용어
- quantification
- Kaggle
- LeNet-5
- timestamp-aware frame encoder
- jmeter
- MySQL
- leetcode
- secure-file-priv
- Linux
- error
- long video understanding
- 백준
- Python
- Artificial Intelligence
- hackerrank
- autogluon
- ma-lmm
- q-former
- multimodal machine learning
- timechat
- tensorflow
- sliding video q-former
- transference
- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Server
- Github
- CNN
- memory bank
- Anaconda
- 코딩테스트
- 용어
- quantification
- Kaggle
- LeNet-5
- timestamp-aware frame encoder
- jmeter
- MySQL
- leetcode
- secure-file-priv
- Linux
- error
- long video understanding
- 백준
- Python
- Artificial Intelligence
- hackerrank
- autogluon
- ma-lmm
- q-former
- multimodal machine learning
- timechat
- tensorflow
- sliding video q-former
- transference
- Today
- Total
Juni_DEV
[Python, HackerRank] Sparse Arrays 본문
주어진 문제
There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results.
Example
stringList = ['ab','ab','abc']
queries = ['ab','abc','bc']
There are 2 instances of 'ab', 1 of 'abc' and 0 of 'bc'. For each query, add an element to the return array, results = [2,1,0].
Function Description
Complete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in stringList.
matchingStrings has the following parameters:
- string stringList[n] - an array of strings to search
- string queries[q] - an array of query strings
Returns
- int[q]: an array of results for each query
Input Format
The first line contains and integer , the size of .
Each of the next lines contains a string .
The next line contains , the size of .
Each of the next lines contains a string .
Constraints
- 1<=n<=1000
- 1<=q<=1000
- 1<= |stringList[i]|, |queries[i]|<=20
Sample Input 1
4
aba
baba
aba
xzxb
3
aba
xzxb
ab
Sample Output 1
2
1
0
Explanation 1
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.
Sample Input 2
3
def
de
fgh
3
de
lmn
fgh
Sample Output 2
1
0
1
Sample Input 3
13
abcde
sdaklfj
asdjf
na
basdn
sdaklfj
asdjf
na
asdjf
na
basdn
sdaklfj
asdjf
5
abcde
sdaklfj
asdjf
na
basdn
Sample Output 3
1
3
4
3
2
풀이
def matchingStrings(stringList, queries):
# Write your code here
answer = []
for q in queries:
cnt =0
for s in stringList:
if q==s :
cnt +=1
answer.append(cnt)
return answer
'Coding Interview' 카테고리의 다른 글
[Python, HackerRank] Divisible Sum Pairs (0) | 2023.04.19 |
---|---|
[Python, HackerRank] Camel Case 4 (0) | 2023.04.19 |
[Python, LeetCode] 9. Palindrome Number (0) | 2023.04.14 |
[Python, HackerRank] Breaking the Records (0) | 2023.04.14 |
[Python, LeetCode] 1. Two Sum (0) | 2023.04.14 |