Skip to content

Latest commit

 

History

History

distant-barcodes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

< Previous                  Next >

In a warehouse, there is a row of barcodes, where the i-th barcode is barcodes[i].

Rearrange the barcodes so that no two adjacent barcodes are equal.  You may return any answer, and it is guaranteed an answer exists.

 

Example 1:

Input: [1,1,1,2,2,2]
Output: [2,1,2,1,2,1]

Example 2:

Input: [1,1,1,1,2,2,3,3]
Output: [1,3,1,3,2,1,2,1]

 

Note:

  1. 1 <= barcodes.length <= 10000
  2. 1 <= barcodes[i] <= 10000
 

Related Topics

[Heap] [Sort]

Hints

Hint 1 We want to always choose the most common or second most common element to write next. What data structure allows us to query this effectively?