code: func (t *Topic) validatePartitionAssignments(brokers []int32, assignment PartitionList) error {
  	if len(assignment) == 0 {
  		return ErrInvalidPartitionCount
  	}
  
  	// get the first replica count to compare against. Every partition should have the same.
  	var replicaCount int
  	for _, part := range assignment {
  		replicaCount = len(part.Replicas)
  		break
  	}
  	if replicaCount == 0 {
  		return ErrInvalidReplicationFactor
  	}
  
  	// ensure all ids are unique and sequential
  	maxPartitionID := int32(-1)
  	partitionIDmap := make(map[int32]struct{}, len(assignment))
  
  	for _, part := range assignment {
  		if part == nil {
  			continue
  		}
  		if maxPartitionID < part.ID {
  			maxPartitionID = part.ID
  		}
  		partitionIDmap[part.ID] = struct{}{}
  
  		// all partitions require the same replica count
  		if len(part.Replicas) != replicaCount {
  			return ErrInvalidReplicaCount
  		}
  
  		rset := make(map[int32]struct{}, replicaCount)
  		for _, r := range part.Replicas {
  			// replica must be assigned to a valid broker
  			found := false
  			for _, b := range brokers {
  				if r == b {
  					found = true
  					break
  				}
  			}
  			if !found {
  				return ErrInvalidBroker
  			}
  			rset[r] = struct{}{}
  		}
  		// broker assignments for a partition must be unique
  		if len(rset) != replicaCount {
  			return ErrReplicaBrokerOverlap
  		}
  	}
  
  	// ensure all partitions accounted for
  	if int(maxPartitionID) != len(assignment)-1 {
  		return ErrMissingPartitionID
  	}
  
  	// ensure no duplicate ids
  	if len(partitionIDmap) != len(assignment) {
  		return ErrDuplicatePartitionID
  	}
  
  	return nil
  }
docs: // validatePartitionAssignments ensures that all partitions are assigned to valid brokers,
  // have the same number of replicas, and each replica is assigned to a unique broker