[HUAWEI OD machine test real questions 2023B volume JAVA&JS] longest continuous subsequence

Huawei OD2023 (B volume) machine test question bank is fully covered, click here for the guide to brushing the questions

longest contiguous subsequence

Knowledge point array sliding window

Time limit: 2s Space limit: 100MB Limited language: unlimited

Title description:

There is a sequence of N positive integers. Given an integer sum, find the longest continuous subsequence so that their sum is equal to sum, return the length of this subsequence, or return -1 if there is no sequence that meets the requirements.

Enter a description:

Sequence: 1,2,3,4,2

sum:6

Output description:

Sequence length: 3

Supplementary note:

The input sequence is only composed of numbers and English commas, and the numbers are separated by English commas;

Sequence length: 1 <= N <= 200;

The input sequence does not consider abnormal conditions, and the title ensures that the input sequence meets the requirements.

Example 1

enter:

1,2,3,4,2
6

output:

3

Description ÿ

Guess you like

Origin blog.csdn.net/qq_34465338/article/details/130982967