i-th parcel carries label labels[i]. An operator takes several **consecutive** parcels off the belt and wants at least two of them to share a label.
Return the smallest number of consecutive parcels that must be taken. If no two parcels on the belt share a label, return -1.labels=[5, 2, 8, 2, 5, 8] → 3
The stretch [2, 8, 2] of length 3 holds two parcels labelled 2. For labels 5 and 8 the stretches are longer: 5 and 4.
labels=[1, 2, 3] → -1
All labels differ, so the answer is -1.
labels=[5, 2, 8, 2, 5, 8]
3
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.