모든 챌린지
보통 0명 해결 정답률 0%

Largest Adjacent-Digit Product

Take every contiguous window of span digits and multiply its digits.

문제

Take every contiguous window of span digits and multiply its digits. Return the largest product. Leading zeros are ordinary digits; a window containing zero has product zero. Do not reorder or skip digits.

Implement largest_adjacent_digit_product(digits, span).

Input

digits: The digit sequence, including any leading zeros.

span: The exact number of adjacent digits in a window.

Output

Return the greatest product over all windows of this width.

제약 조건

1 ≤ digit-string length ≤ 100,000. Characters are 0…9. 1 ≤ span ≤ min(18, length). All products fit signed 64-bit.

예시

예시 1
입력:
span = 2
digits = "23405"

예상 출력:
expected = 12
입력:
long long span = 2;
std::string digits = "23405";

예상 출력:
long long expected = 12;
입력:
long span = 2;
string digits = "23405";

예상 출력:
long expected = 12;

설명

The windows 23, 34, 40, and 05 have products 6, 12, 0, and 0. The largest is 12.

예시 2
입력:
span = 3
digits = "102"

예상 출력:
expected = 0
입력:
long long span = 3;
std::string digits = "102";

예상 출력:
long long expected = 0;
입력:
long span = 3;
string digits = "102";

예상 출력:
long expected = 0;

설명

There is only one width-three window. It contains zero, so 1 × 0 × 2 = 0.

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.