Skip to content

Practice Distant Barcodes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1054
LeetCode Problem

Distant Barcodes

Problem Statement

In a warehouse, there is a row of barcodes, where the ith 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.

Source: Distant Barcodes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

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

Related LeetCode Problems

Practice more problems similar to Distant Barcodes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.