Sparse Arrays

  • + 0 comments

    Swift solution:

    func matchingStrings(strings: [String], queries: [String]) -> [Int] {
        queries.reduce(into: [Int]()) { partialResult, query in
            let occurrences = strings
                .filter { $0 == query }
                .count
            partialResult.append(occurrences)
        }
    }