[Huawei OD machine test 2023 latest] The vehicle with the most colors (100% C language problem solution)

topic description

At a narrow intersection, only one vehicle can pass per second, assuming that there are only 3 colors of vehicles, find out the number of vehicles with the most colors that pass within N seconds.

The three colors are numbered 0, 1, 2

Please note: here is the assumption of 3 colors, there are more than 3 colors in the actual test! ! ! ! ! !

enter description

The first line enters the color information of the vehicle passed

[0,1,1,2] represents the colors of vehicles that pass in 4 seconds are 0 , 1 , 1 , 2

The input in the second line is the statistical time window, integer, and the unit is second

output description

Outputs the number of vehicles with the most color that passed within the specified time window.

Example

<
enter 0 1 2 1
3
output 2
illustrate Each color can appear up to 2 times in a 3 second time window. For example: [1,2,1]

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/130471617