• + 0 comments

    Using bitwise "|" and Binary is way more better to find max subject

    max_subject = 0
    max_team = 0
    
    for first_i in range(len(people)):
        for second_i in range(first_i + 1, len(people)):
            first_subject = people[first_i]
            second_subject = people[second_i]
    
            i_k = int(first_subject, 2)
            i_j = int(second_subject, 2)
    
            current_max_sub = bin(i_k | i_j)[2:].count("1")
    
            if  current_max_sub > max_subject:
                max_subject = current_max_sub
                max_team = 1
            elif current_max_sub == max_subject:
                max_team += 1
    
    return [max_subject, max_team]
    

    *