Tap here to switch tabs
Problem
Submissions

Problem: Partition String Into Substrings With Values at Most K

med
30 min
Try to solve the Partition String Into Substrings With Values at Most K problem.

Statement

You are given a string s consisting of digits and an integer k.

A partition of s is called valid if the numeric value of each contiguous substring in the partition is at most k.

Return the minimum number of substrings in a valid partition of s. If it is impossible to partition s such that every substring has a value at most k, return −1-1.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is a digit from ′1′'1' to ′9′'9'

  • 1≤1 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Partition String Into Substrings With Values at Most K

med
30 min
Try to solve the Partition String Into Substrings With Values at Most K problem.

Statement

You are given a string s consisting of digits and an integer k.

A partition of s is called valid if the numeric value of each contiguous substring in the partition is at most k.

Return the minimum number of substrings in a valid partition of s. If it is impossible to partition s such that every substring has a value at most k, return −1-1.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is a digit from ′1′'1' to ′9′'9'

  • 1≤1 \leq k ≤109\leq 10^9