Hint was really helpful


#1

Easy to understand java solution

public class Solution {
public int cntBits(ArrayList<Integer> A) {
    
    Map<Integer, Integer> zeroMap = new HashMap<>();
    Map<Integer, Integer> oneMap = new HashMap<>();
    
    for(Integer num: A){
        for(int i = 0; i < 32; i++){
            if(((1<<i)&num) !=0) {
                oneMap.put(i, oneMap.getOrDefault(i,0)+1);
            }else {
                 zeroMap.put(i, zeroMap.getOrDefault(i,0)+1);
            }
        }
    }
    
    int mod = (int)1e9+7;
    long ans = 0l;
    
    for(Integer num: A){
        for(int i =0; i < 32; i++){
            if(((1<<i)&num) !=0) {
                ans = (ans + zeroMap.getOrDefault(i,0))%mod;
            }else {
                  ans = (ans +oneMap.getOrDefault(i,0))%mod;
            }
        }
        
    }
    return (int)ans;
}

}