Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Distant Barcodes

XPChallenge Points: 20
levelLevel: Medium

You’re given an array barcodes where each element represents a barcode number.
You need to rearrange them so that no two adjacent elements are equal.
It’s guaranteed that at least one valid arrangement exists.

Example 1:

Input: barcodes = [1,1,1,2,2,2]

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

Example 2:

Input: barcodes = [1,1,1,1,2,2,3,3]

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

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result