Sparse Arrays

Sort by

recency

|

395 Discussions

|

  • + 0 comments
    function matchingStrings(strings: string[], queries: string[]): number[] {
        return queries.map((q: string): number => strings.filter((s: string) => q === s).length)
    }
    
  • + 0 comments

    Scala

        def matchingStrings(strings: Array[String], queries: Array[String]): Array[Int] = {
                queries.map(q => strings.count(_ == q))
        }
    
  • + 0 comments
    #For Python
    
    def matchingStrings(strings, queries):
        result = [0] * len(queries)
        for i in range(len(queries)):
            query = queries[i]
            for j in range(len(strings)):
                if query == strings[j]:
                    result[i] += 1
        return result
    
  • + 0 comments

    Code in Go, Please suggest if any optimization can be done.

    func matchingStrings(strings []string, queries []string) []int32 { // Write your code here var count int32=0 var stringCount[] int32 for _,query:=range queries{ for _,match:=range strings{ if(query == match){ count = count + 1 } } stringCount = append(stringCount,count) count = 0 }

    return stringCount }

  • + 0 comments

    My C# solution

     public static List<int> matchingStrings(List<string> strings, List<string> queries)
        {
            return queries.Select(q => 
                strings.Count(s => s == q))
                .ToList<int>();
        }