Sort by

recency

|

1033 Discussions

|

  • + 0 comments

    Just as gemstones are minerals found in every rock of a collection, certain elements define a great racing game—speed, strategy, and precision. In gaming, discovering these essential features can enhance the experience, much like identifying gemstones in nature.

    At Drive Zone Online, we explore what makes racing games truly stand out, offering insights, guides, and updates for enthusiasts. Whether it's mastering techniques or finding the best modifications, understanding the core elements of a game can make all the difference.

  • + 0 comments

    Here are my c++ approaches of solving this problem, video explanation here : https://youtu.be/EjhdJXN3a3c

    Solution 1 : Using a list of all possible characters

    int gemstones(vector<string> arr) {
        int result = 0;
        string liste = "abcdefghijklmnopqrstuvwxyz";
        for(int j = 0; j < liste.size(); j++){
            int cp = 0;
            for(int i = 0; i < arr.size(); i++){
                if(arr[i].find(liste[j]) != string::npos) cp++;
            }
            if(cp == arr.size())result++;
        }
        return result;
    }
    

    Solution 2 : Using set of the shortest element of the array of string

    string getShortest(vector<string> arr) {
        string result = arr[0];
        for(int i = 1; i < arr.size(); i++){
            if(arr[i].size() < result.size()) result = arr[i];
        }
        return result;
    }
    int gemstones(vector<string> arr) {
        int result = 0;
        string shortest = getShortest(arr);
        set<char> liste(shortest.begin(), shortest.end());
        for(auto j = liste.begin(); j != liste.end(); j++){
            int cp = 0;
            for(int i = 0; i < arr.size(); i++){
                if(arr[i].find(*j) != string::npos) cp++;
            }
            if(cp == arr.size())result++;
        }
        return result;
    }
    
  • + 0 comments

    Python3

    def gemstones(arr):
        # Write your code here
        
        s = set(arr[0])
        count = 0
        
        for i in s:
            if all(map(lambda x: i in x, arr)):
                count += 1
                
        return count
        
    
  • + 0 comments

    Solution from my side

    def gemstones(arr):
        count = 0
        data = set(list("".join(arr)))
        for item in data:
            temp = True
            for i in range(len(arr)):
                if(item not in arr[i]):
                    temp = False
                    break
            if(temp):
                count +=1
        return count
    
  • + 0 comments

    My answer with Typescript

    function gemstones(arr: string[]): number {
        // sort stones by length
        let stones = arr.sort((a, b) => a.length - b.length)
        // take the smallest stone, get collection of gems inside it
        let gems = Array.from(new Set<string>(stones.shift().split('')))
        // the rest of stones should have gems to be count as gemstone.
        return gems.filter(gem => stones.every(stone => stone.includes(gem))).length
    }