current position:Home>HUAWEI Machine Test Real Questions Java Realization [Vehicles with the Most Colors] [2022.11 Q4 New Questions]

HUAWEI Machine Test Real Questions Java Realization [Vehicles with the Most Colors] [2022.11 Q4 New Questions]

2022-11-24 20:27:46MISAYAONE

Table of Contents

Subject

Thinking

Test site

Code


Title

Title content
At a narrow intersection, only one car can pass per second, assuming that there are only 3 colors of good cars, find out the cars with the most colors that pass by within N secondsquantity.

The three color numbers are 0, 1, 2

Enter description
The first line is the color information of the vehicle passed

[0,1,1,2] means that 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 colors that pass within the specified time window.

Example
Example 1:
Input

0 1 2 1
3
output

2

Example explanation

There is a maximum of 2 occurrences of each color within the 3 second time window.For example

copyright notice
author[MISAYAONE],Please bring the original link to reprint, thank you.
https://caren.inotgo.com/2022/328/202211242020420637.html

Random recommended