Given barcodes represented as integers, rearrange them so that no two adjacent barcodes are equal. Frequency-driven placement or bucket assignment is the standard strategy for this bounded-label problem.
barcodes = array of integers
rearranged array with no equal adjacent values
Example 1:
Input:
barcodes = [1,1,1,2,2,2]
Output:
[1,2,1,2,1,2]
Explanation:
High-frequency values are interleaved to avoid adjacent duplicates.
Example 2:
Input:
barcodes = [1,1,1,1,2,2,3,3]
Output:
[1,2,1,3,1,2,1,3]
Explanation:
The most frequent value is spaced out across the array.