Given an array [1, 2, 2, 3, 4, 4, 5], is it possible to shuffle the array while preventing the duplicates to be next to each other?
For example:
[1, 2, 3, 4, 2, 5, 4]is an acceptable solution.[1, 2, 3, 4, 4, 2, 5]is not an acceptable solution since4is next to another4
This seems like a simple question but after thinking about it, the solution seems complicated. Any help is greatly appreciated, thanks!!