public static List<Integer> getRackAlternatedBrokerList(Map<Integer, String> brokerRackMap) {
        Map<String, Iterator<Integer>> brokersIteratorByRack = new HashMap<>();
        getInverseMap(brokerRackMap).forEach((rack, brokers) -> brokersIteratorByRack.put(rack, brokers.iterator()));
        String[] racks = brokersIteratorByRack.keySet().toArray(new String[0]);
        Arrays.sort(racks);
        List<Integer> result = new ArrayList<>();
        int rackIndex = 0;
        while (result.size() < brokerRackMap.size()) {
            Iterator<Integer> rackIterator = brokersIteratorByRack.get(racks[rackIndex]);
            if (rackIterator.hasNext())
                result.add(rackIterator.next());
            rackIndex = (rackIndex + 1) % racks.length;
        }
        return result;
    }
Given broker and rack information, returns a list of brokers alternated by the rack. Assume
this is the rack and its brokers:
<pre>
rack1: 0, 1, 2
rack2: 3, 4, 5
rack3: 6, 7, 8
</pre>
This API would return the list of 0, 3, 6, 1, 4, 7, 2, 5, 8
<br>
This is essential to make sure that the assignReplicasToBrokers API can use such list and
assign replicas to brokers in a simple round-robin fashion, while ensuring an even
distribution of leader and replica counts on each broker and that replicas are
distributed to all racks.
server-common/src/main/java/org/apache/kafka/admin/AdminUtils.java