A shipping center places parcels in a row from the lightest to the heaviest.
Several parcels may have the same recorded weight. Find the first and last positions in the row containing parcels with a requested weight.
ParcelRow
List<Integer> locateWeightGroup( List<Integer> parcelWeights, int wantedWeight )
parcelWeights: The parcel weights in their row order.wantedWeight: The parcel weight to locate.Return a list containing the first and last positions where wantedWeight appears.
Positions are indexed from 0, and both returned positions are inclusive.
If no parcel has the requested weight, return List.of(-1, -1).
parcelWeights is sorted in non-decreasing order.O(log n) time, where n is the number of parcels.0 ≤ parcelWeights.size() ≤ 100,0001 ≤ parcelWeights.get(i) ≤ 1,000,000,0001 ≤ wantedWeight ≤ 1,000,000,000parcelWeights is sorted in non-decreasing order.null. locateWeightGroup( parcelWeights = List.of(150, 220, 220, 220, 480, 650), wantedWeight = 220 )
Output: List.of(1, 3)
Parcels weighing 220 grams occupy positions 1 through 3 in the row.
locateWeightGroup( parcelWeights = List.of(90, 140, 140, 275, 430), wantedWeight = 200 )
Output: List.of(-1, -1)
No parcel in the row weighs 200 grams.
locateWeightGroup( parcelWeights = List.of(75, 100, 160, 240), wantedWeight = 160 )
Output: List.of(2, 2)
Only the parcel at position 2 has the requested weight.
locateWeightGroup( parcelWeights = List.of(), wantedWeight = 500 )
Output: List.of(-1, -1)
The row is empty, so the requested weight cannot be found.