ACM ICPC Team: Hackerank
This part can be optimized a bit, in terms of length.

List&lt;Integer&gt; mapping = new ArrayList&lt;&gt;();
mapping.add(i+1);
mapping.add(j+1);

if(counts.containsKey(count)){
    List&lt;List&lt;Integer&gt;&gt; existingMappings = counts.get(count);
    existingMappings.add(mapping);
    counts.put(count, existingMappings);
}else{
    List&lt;List&lt;Integer&gt;&gt; newMappings = new ArrayList&lt;&gt;();
    newMappings.add(mapping);
    counts.put(count, newMappings);
}


Java 8 maps have computeIfAbsent. You can use this to "getOrCreate" the existing mapping like so:

List&lt;Integer&gt; mapping = new ArrayList&lt;&gt;();
mapping.add(i+1);
mapping.add(j+1);

counts.computeIfAbsent(count, k -&gt; new ArrayList&lt;&gt;()).add(mapping);


Additionally, you do this:

    List&lt;List&lt;Integer&gt;&gt; existingMappings = counts.get(count);
    existingMappings.add(mapping);
    counts.put(count, existingMappings);


There is no need to put something back into the map when you have retrieved it, because you are retrieving a pointer to a list, and you're using it to add to a list. See this Ideone that lists you put and later retrieve from the map are the same lists.

Okay, so back to this snippet.

List&lt;Integer&gt; mapping = new ArrayList&lt;&gt;();
mapping.add(i+1);
mapping.add(j+1);

counts.computeIfAbsent(count, k -&gt; new ArrayList&lt;&gt;()).add(mapping);


The new ArrayList constructor can take an initialSize argument. Since you're only going to be adding two integers to the list, you could provide this information and save memory space.

List&lt;Integer&gt; mapping = new ArrayList&lt;&gt;(2);


Your algorithm could be more optimized - there's no need to count topic knowledge for a team if they know 7 topics together and there's only 6 topics left to check and the top team currently knows 14 topics. Similarily, there's no reason to store how much topics each team knows, only the teams that know the largest amount of topics, and the largest amount of topics you have currently found.

However, I think that when we look at the loops, you can't really get rid of them.

You see, there's two loops needed to make the teams (iterating people over people), and one loop needed to check the topics (iterating over topics). There are clever tricks you could use where you take the binary string and convert it to an integer, but when you do that, you're looping over the characters in the binary string - it has to read the string, after all. You just don't use a for loop.

So we're doomed to have at least 3 loops. What you CAN do is take the counting loop and put it in a separate function. That would "get rid" of one of the loops. Your static analyzer is not built with the idea of such challenges in mind - to see a method with 3 nested loops usually means the method is doing too much work.