• + 0 comments
    public static List<Integer> matchingStrings(List<String> stringList, List<String> queries) {
    // Write your code here
    // Use a HashMap to store the frequency of each string in stringList
        Map<String, Integer> frequencyMap = new HashMap<>();
    
        // Count occurrences of each string in stringList
        for (String str : stringList) {
            frequencyMap.put(str, frequencyMap.getOrDefault(str, 0) + 1);
        }
    
        // Prepare the result list
        List<Integer> result = new ArrayList<>();
    
        // Retrieve frequency for each query
        for (String query : queries) {
            result.add(frequencyMap.getOrDefault(query, 0));
        }
    
        return result;
    }