[Huawei OD machine test real questions] 100% pass rate of the leftmost redundant coverage substring (python) super detailed code comment code optimization

[Huawei OD machine test real questions 2022&2023] real test catalog @click here @
[Huawei OD machine test real questions] signal transmission and reception & trial reading & @click here @
[Huawei OD machine real test questions] rent a car to ride the greenway & trial reading & @点here@

leftmost redundant cover substring

Sliding window for knowledge points
Time limit: 1s Space limit: 256MB Limited language: unlimited

Title description:

Given 2 characters s1 and s2 and a positive integer k, where s1 has a length of n1 and s2 has a length of n2, select a substring in s2 that satisfies: the length of the substring is n1+k, and the substring
contains
all the letters in s1
. The number of occurrences of each letter of the substring is not less than the corresponding letter in s1.
We say that s2 covers s1 redundantly with length k. Given s1, s2 and k, find the subscript of the first element of the substring of the leftmost s2 redundantly covering s1 with length k, if not return -1

Example:

 

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/130672538