Sort by

recency

|

2428 Discussions

|

  • + 0 comments

    Python

    def matchingStrings(stringList, queries):
        return [stringList.count(each) if each in stringList else 0 for each in queries]
    
  • + 0 comments

    Another simple but a bit less efficient python solution:

    def matchingStrings(stringList, queries):
        count = []
        for i in queries:
            occ = [j for j in stringList if i == j]
            count.append(len(occ))
        return count
    
  • + 0 comments

    A very simple python solution:

    def matchingStrings(stringList, queries):
        return [stringList.count(i) for i in queries]
    		
    
  • + 0 comments

    JavaScript Solution:

    let res=[];
    let count=0;
    queries.map(s=>{
        count=0;
        stringList.map(q=>{
            if(s===q) count++;
        })
        res.push(count);
    })
    return res;
    
  • + 0 comments

    Here's my easy understandable solution in C++, just ask gpt to do formatting of code (if not presentable).

    include

    using namespace std; void matching_func(string str_list[], int str_size, string que_list[], int que_size) { // this function will match the queries and str indexes and // also directly print the results. int result; for(int q_index = 0; q_index < que_size; q_index++) { result = 0; // to make results 0 for each query start for(int str_index = 0; str_index < str_size; str_index++) {
    // this inner loop will match specific query index element to string index elements. if(que_list[q_index] == str_list[str_index]) { result++; // if matched, then only increase the value } } cout << result << endl; } } void input_arr(int size, string arr[]) { for (int index = 0; index < size; index++) { cin >> arr[index]; } } int main() { int size_string_list, size_query_list; cin >> size_string_list; string string_list[size_string_list]; input_arr(size_string_list, string_list); cin >> size_query_list; string query_list[size_query_list]; input_arr(size_query_list, query_list); matching_func(string_list, size_string_list, query_list, size_query_list); // here we have just taken the input of size and list return 0; }