"ACM ICPC Team" challenge on Hackerrank... Easy? This challenge took me awhile to figure out, and it's characterized as &quot;easy,&quot; so I'm sorta wondering what I missed.

Problem Statement
You are given a list of N people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can know. And also find out how many teams can know that maximum number of topics.
N = number of people = number of lines of input. 2 ≤ N ≤ 500
M = number of topics = number of bits per line. 1 ≤ M ≤ 500

Sample Input

4 5
10101
11100
11010
00101

Sample Output

5
2

My solution below uses a BitArray object, because all of the test cases except one have more than 32 topics.
I'm wondering if HackerRank wasn't expecting something a little more fundamental... Maybe some clever string twiddling hack that I don't know about?
Most of the test cases took about .86 seconds to execute, which seems quite slow to me.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

class Solution {
    static void Main(String[] args) 
    {
        string input = Console.ReadLine();
        string[] inputs = input.Split(new char[] {' '});
        
        int numberOfMembers = int.Parse(inputs[0]);
        int numberOfTopics = int.Parse(inputs[1]);
        
        var bitArray = new BitArray[numberOfMembers];
        for (int n = 0; n &lt; numberOfMembers; n++)
        {
            bitArray[n] = new BitArray(numberOfTopics);
            
            string memberTopics = Console.ReadLine();
            for(int m = 0; m &lt; numberOfTopics; m++)
                bitArray[n].Set(m, memberTopics[m] == '1');
        }

        // Find the maximum number of topics that all the teams know.
        int maxTopics = 0;
        for(int i = 0; i &lt; numberOfMembers - 1; i++)
            for (int j = i + 1; j &lt; numberOfMembers; j++)
            {
                int numberOfTeamTopics = NumberOfSetBits(new BitArray(numberOfTopics).Or(bitArray[i]).Or(bitArray[j]));
                if (numberOfTeamTopics &gt; maxTopics)
                    maxTopics = numberOfTeamTopics;
            }
        
        // Find the number of teams that know the maximum number of topics.
        int maxTeams = 0;
        for(int i = 0; i &lt; numberOfMembers - 1; i++)
            for (int j = i + 1; j &lt; numberOfMembers; j++)
            {
                int numberOfTeamTopics = NumberOfSetBits(new BitArray(numberOfTopics).Or(bitArray[i]).Or(bitArray[j]));
                if (numberOfTeamTopics == maxTopics)
                    maxTeams++;
            }
        
        Console.WriteLine(maxTopics);
        Console.WriteLine(maxTeams);
    }
    
    static int NumberOfSetBits(BitArray b)
    {
        int count = 0;
        for (int i = 0; i &lt; b.Length; i++)
            if (b.Get(i))
                count++;
        return count;
    }
}
Some improvements:

Combine loops

int maxTopics = 0;
int maxTeams = 0;
for(int i = 0; i &lt; numberOfMembers - 1; i++)
    for (int j = i + 1; j &lt; numberOfMembers; j++)
    {
        int numberOfTeamTopics 
            = NumberOfSetBits(new BitArray(numberOfTopics).Or(bitArray[i]).Or(bitArray[j]));

        if (numberOfTeamTopics &gt; maxTopics)
        {
            maxTopics = numberOfTeamTopics;
            maxTeams = 1;
        }
        else if (numberOfTeamTopics == maxTopics)
        {
            maxTeams++; 
        }
    }


Use a better algorithm for counting set bits

public static Int32 NumberOfSetBits(BitArray bitArray)
{
    Int32[] ints = new Int32[(bitArray.Count &gt;&gt; 5) + 1];
    bitArray.CopyTo(ints, 0);
    Int32 count = 0;

    // fix for not truncated bits in last integer that may have been set to true with SetAll()
    ints[ints.Length - 1] &amp;= ~(-1 &lt;&lt; (bitArray.Count % 32));

    for (Int32 i = 0; i &lt; ints.Length; i++)
    {
        Int32 c = ints[i];

        // magic (http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel)
        unchecked
        {
            c = c - ((c &gt;&gt; 1) &amp; 0x55555555);
            c = (c &amp; 0x33333333) + ((c &gt;&gt; 2) &amp; 0x33333333);
            c = ((c + (c &gt;&gt; 4) &amp; 0xF0F0F0F) * 0x1010101) &gt;&gt; 24;
        }
        count += c;
    }
    return count;
}


New execution time: 0.12 seconds.