Sort by

recency

|

1233 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
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner in = new Scanner(System.in);
            int N = in.nextInt(); //number of people
            int M = in.nextInt(); //number of topics
            String[] person_info = new String[N];
            
            for (int i = 0; i < N; i++) 
                person_info[i] = in.next();
            long teams = 0;
            long max_covered = 0;
            long matched_topics = 0;
            for (int i = 0; i < N; i++) {
                
                for (int k = i + 1; k < N; k++) {
                    matched_topics = 0;
                    for (int j = 0; j < M; j++) {
               
                        if (person_info[i].charAt(j) - '0' > 0 || person_info[k].charAt(j) - '0' > 0)
                            matched_topics++;
                    }
                    if (matched_topics == max_covered)
                        teams++;
                    else if (matched_topics > max_covered) {
                        max_covered = matched_topics;
                        teams = 1;   
                    }
                }
               
                
                
           
            }
            
            System.out.println(max_covered);
            System.out.println(teams);
            /*for (int i = 0; i < N; i++) {
                System.out.printf("%sn", person_info[i]);
            }*/
            in.close();
        }
    }
    
  • + 0 comments
    from itertools import combinations
    from collections import Counter
    def acmTeam(topic):
        a=list(combinations(topic,2))
        p=[]
        for i in a:
          m=list(filter(lambda x :'1' in x,zip(i[0],i[1])))
          p.append(len(m))
        return max(Counter(p).items())
    
  • + 0 comments

    def acmTeam(topic):

        res = []
        for i in range(len(topic)):  
             j = i+1
                while j<len(topic):
            rs = str(bin(int(topic[i], 2) | int(topic[j], 2)))[2:]
            res.append(len([1 for z in rs if z=='1']))
            j +=1
    return [max(res), res.count(max(res))]
    
  • + 0 comments

    Python 3 - this challenge taught me to utilise binary string operations. It took some time but I decided that this was the better solution than a triple nested loop.

    def acmTeam(topic):
        int_masks = [int(topic_i, 2) for topic_i in topic] # convert to integers from binary string
    
        known_topics = 0
        known_topics_people = 0
    
        for i in range(len(topic)):
            for j in range(i +1, len(topic)): #we start iterating from a new i !!
                overlap = bin(int_masks[i] | int_masks[j]).count("1")
                if overlap > known_topics:
                    known_topics = overlap
                    known_topics_people = 1
                elif overlap == known_topics:
                    known_topics_people += 1
                
        return known_topics, known_topics_people