Tap here to switch tabs
Problem
Submissions

Problem: Total Waviness of Numbers in Range I

med
30 min
Try to solve the Total Waviness of Numbers in Range I problem.

Statement

Given two integers num1 and num2, calculate the sum of the waviness of all integers in the inclusive range [num1, num2].

The waviness of an integer is defined as the total number of peak digits and valley digits it contains:

  • A digit is considered a peak if it is strictly greater than both its left and right adjacent digits.

  • A digit is considered a valley if it is strictly less than both its left and right adjacent digits.

First and last digits of a number cannot be peaks or valleys. Numbers with fewer than 33 digits have a waviness of 00.

Return the total waviness of all numbers in the given range.

Constraints:

  • 1≤1 \le num1 ≤\le num2 ≤105\le 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Total Waviness of Numbers in Range I

med
30 min
Try to solve the Total Waviness of Numbers in Range I problem.

Statement

Given two integers num1 and num2, calculate the sum of the waviness of all integers in the inclusive range [num1, num2].

The waviness of an integer is defined as the total number of peak digits and valley digits it contains:

  • A digit is considered a peak if it is strictly greater than both its left and right adjacent digits.

  • A digit is considered a valley if it is strictly less than both its left and right adjacent digits.

First and last digits of a number cannot be peaks or valleys. Numbers with fewer than 33 digits have a waviness of 00.

Return the total waviness of all numbers in the given range.

Constraints:

  • 1≤1 \le num1 ≤\le num2 ≤105\le 10^5