Sort by

recency

|

1245 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

    Typescript:

    function acmTeam(topic: string[]): number[] {
        // Write your code here
        const arrayOfMaximumTopics: number[] = [];
        let maximumTopics = 0;
        let numberOfTeams = 0;
        let totalAttendees: number = topic.length;
        
        for (let i = 0; i < totalAttendees - 1; i++) {
            for (let j = i + 1; j < totalAttendees; j++) {
                let topicsOfTeam = 0;
                const topicsCurrentAttendee: string[] = topic[i].split("");
                const topicsNextAttendee: string[] = topic[j].split("");
                
                topicsCurrentAttendee.forEach((el, index) => {
                    if (el === '1' || topicsNextAttendee[index] === '1') {
                        topicsOfTeam++;
                    }
                })
               
                if (topicsOfTeam > maximumTopics) {
                    maximumTopics = topicsOfTeam;
                }
                
                arrayOfMaximumTopics.push(topicsOfTeam);
            }
        }
        
        numberOfTeams = arrayOfMaximumTopics.filter(el => el === maximumTopics).length;
        
        return [maximumTopics, numberOfTeams];
    }
    
  • + 0 comments

    def acmTeam(topic): maxi=0 cou=0 for i in range(len(topic)-1): for j in range(i+1,len(topic)): subj = 0 for m,k in zip(topic[i],topic[j]): if(m=='1' or k=='1'): subj += 1

            if(maxi==subj):
                cou += 1
            elif(maxi<subj):
                cou=1
                maxi=subj
    return maxi,cou
    
  • + 0 comments

    Perl:

    sub acmTeam {
        my $topics = shift;
        my $n = @$topics;
        my $m = $n > 0? length($topics->[0]): 0;
        my $max = 0;
        my $max_n = 0;
        for my $i (0 .. $n-2) {
            for my $j ($i + 1 .. $n-1) {
                my $st = 0;
                $st += (substr($topics->[$i], $_, 1) eq '1' || substr($topics->[$j], $_, 1) eq '1'? 1: 0) for (0..$m-1);
                if($st > $max) {
                    $max = $st;
                    $max_n = 1;
                } elsif($st == $max) {
                    ++$max_n;
                }
            }
        }
        return ($max, $max_n);
    }
    
  • + 0 comments

    def acmTeam(topic): combinations = list(itertools.combinations(topic, 2)) subject_counts = []

    for t1, t2 in combinations:
        sub = 0
        for a, b in zip(t1, t2):
            if a == '1' or b == '1':
                sub += 1
        subject_counts.append(sub)
    
    max_subjects = max(subject_counts)
    max_teams = subject_counts.count(max_subjects)
    
    return [max_subjects, max_teams]