A distribution center places packages in a line on a conveyor belt. Each package has an inspection code.
A package with an even code is domestic, while a package with an odd code is international.
A conveyor segment is correctly arranged if domestic and international packages alternate throughout the segment.
For every requested segment, determine whether it is correctly arranged.
ConveyorInspector
List<Boolean> validateSegments( List<Integer> packageCodes, List<String> inspectionRanges )
packageCodes: The inspection codes of the packages in conveyor order.inspectionRanges: Each string has the format "start,end" and describes an inclusive segment.Return a list containing one boolean value for each inspection range, in the same order as the input.
A value is true if every pair of neighboring packages in that segment contains one even code and one odd code. Otherwise, it is false.
0.1 ≤ packageCodes.size() ≤ 100,0001 ≤ packageCodes[i] ≤ 100,0001 ≤ inspectionRanges.size() ≤ 100,000inspectionRanges contains exactly two integers separated by one comma, with no spaces."start,end", 0 ≤ start ≤ end < packageCodes.size() . validateSegments( packageCodes = [18, 7, 12, 5, 9], inspectionRanges = ["0,3", "1,4", "2,2"] )
Output: [true, false, true]
[18, 7, 12, 5] alternates between even and odd codes.[7, 12, 5, 9] ends with two neighboring odd codes.12 is correctly arranged. validateSegments( packageCodes = [3, 8, 14, 11, 6, 2], inspectionRanges = ["0,1", "1,3", "2,4", "4,5"] )
Output: [true, false, true, false]
3 and 8 have different parity.8 and 14 are both even.[14, 11, 6] alternates correctly.6 and 2 are both even.