2023 Huawei OD Interview Hand-Teared Real Questions [Find the Largest Consecutive Substring]

topic:

A string of characters consists of "1-10" "AZ", and each character is separated by ",". Find the largest continuous substring. (The character after 10 is A)

Example 1:
Input:
1,2,3,4,5,7,8

Output:
1 2 3 4 5

        There is no original question on the Internet for this question. It is a question given by the interviewer directly sharing the screen. The interview students are required to write code on their own IDEA and take a self-test. At first glance, it is the question of Subject 2 of Huawei OD Trusted Examination. The algorithm idea is relatively simple, but it gives a relatively uncommon scene background.

        In fact, translated, this is a problem of finding the largest continuous substring in an array. Maximum, continuous, and length . When these words come out, students who have answered a lot of questions will probably think of [ sliding window ]. It’s okay if they don’t think of it. Just remember it from now on. . . .

        There is no fancy solution to this question, just use the left and right pointers to determine whether all the characters in the window meet the [continuous] requirement. The only difficulty is the processing of letters . Here we don’t need to convert all letters into numbers, as long as the judgment Just add a few more conditions.

import java.util.Scanner;
import java.util.*;
import java.util.stream.Collectors;

public class Main { 
    public static

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/132908881