Sort by

recency

|

1239 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/fCUW_MhWEW8

    vector<int> acmTeam(vector<string> topic) {
        int h = 0, cp = 0;
        for(int i = 0; i < topic.size() - 1; i++){
            bitset<500> a = bitset<500>(topic[i]);
            for(int j = i + 1; j < topic.size(); j++){
             bitset<500> b = bitset<500>(topic[j]);
             bitset<500> c = a | b;
             int x = c.count();
             if( x > h){h = x; cp = 1;}
             else if( x == h) cp++;
            }
        }
        return {h, cp};
    }   
    
  • + 0 comments
    public static List<int> acmTeam(List<string> topic)
    {
            int m = topic.Count; // member count
            int t = topic[0].Length; // topic count
            List<int> teams = new(); // team known topic counts
            for(int i=0; i < m-1; i++)
            {
                    for(int j=i+1; j < m; j++)
                    {
                        int known = 0;
                        for(int k=0; k < t; k++)
                        {
                            if(topic[i][k]=='1' || topic[j][k]=='1')
                            {
                                    known++;
                                    continue;
                            }
                        }
                        teams.Add(known);   
                    }
            }
            int max = teams.Max();
            int count = teams.Count(t=> t==max);
            return new List<int>{ max, count };
    }
    
  • + 0 comments

    python3:

    from itertools import combinations
    
    def acmTeam(topic):
        # Write your code here
        
        r = [ {i+1 for i,j in enumerate(s) if j == "1"} for s in topic]
             
        x = [ list(u[0].union(u[1])) for u in combinations(r, r=2) ]
        x = list(map(lambda i: len(i), x))
        
        return [max(x), x.count(max(x))] 
    
  • + 0 comments

    Here is my Python solution using itertools!

    def acmTeam(topic):
        teams = list(itertools.combinations(topic, 2))
        subjects = []
        for team in teams:
            known = 0
            for topic in range(len(team[0])):
                if team[0][topic] == "1" or team[1][topic] == "1":
                    known += 1
            subjects.append(known)
        return [max(subjects), subjects.count(max(subjects))]
    
  • + 0 comments
    // i have chnages the given array from topics -> persons. 
    // now understand, it like if person[i][k] == 1, that means ith person knows the topic k. 
    
    function acmTeam(persons) {
        let max = 0; // max topic that the team know 
        let count = 0; // the team which knows the max topics 
        
        for(let i = 0; i < persons.length; i++) { 
            for(let j = i + 1; j < persons.length; j++) {
                let know = 0; 
                for(let k = 0; k < persons[0].length; k++) {
                    if(persons[i][k] === '1' || persons[j][k] === '1'){
                        know += 1; 
                    }
                }
                
                if(know > max) {
                    max = know; 
                    count = 1; // reset the count for the nex max
                }
                else if(know === max){
                    count += 1; // otherwise increase the count, we found another max 
                }
            }
        }
        return [max, count]; 
    		// should i tell you a secret, >> you are g___r___e__a__t 😍!!
       //  Happy Coding 
    }