• + 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