#3785

Minimum Swaps to Avoid Forbidden Values

international master · 1975 · lc hard +32 · 30.3% accepted · 108 likes · top 7%

Description

Given two integer arrays nums and forbidden of length n, perform the minimum number of swaps of elements within nums so that nums[i] != forbidden[i] for every index i, and return that count (or -1 if no arrangement of swaps can satisfy all constraints).

Code

1
2
3