Good algorithm for combining items from N lists into one with balanced distribution?

前端 未结 7 976
北荒
北荒 2020-12-05 20:54

Let\'s say I have the three following lists

A1
A2
A3

B1
B2

C1
C2
C3
C4
C5

I\'d like to combine them into a si

7条回答
  •  無奈伤痛
    2020-12-05 21:27

    • Make a hash table of lists.
    • For each list, store the nth element in the list under the key (/ n (+ (length list) 1))
    • Optionally, shuffle the lists under each key in the hash table, or sort them in some way
    • Concatenate the lists in the hash by sorted key

提交回复
热议问题