The Partition String Into Substrings With Values at Most K problem asks you to partition a numeric string into the minimum number of substrings where each substring's integer value is ≤ k. This coding problem uses greedy: extend the current substring as long as its value stays ≤ k. When a single digit exceeds k, return -1. The string, greedy, and dynamic programming interview pattern is demonstrated.
Google asks this to test greedy string partitioning with a numeric value constraint. The greedy approach — always extend the current partition as far as possible without exceeding k — minimizes the number of partitions.
Greedy extension. Scan characters: maintain current number by extending: curr = curr * 10 + digit. If curr > k, start a new partition (count++, reset curr = digit). If digit > k at any point (even as a single number), return -1. Return final count (initialized to 1 if string is non-empty).
s="165462", k=60.
Numeric string partition problems using a value threshold always use greedy extension: build the current number digit by digit, reset when it exceeds the threshold. The impossible case (single digit > k) must be checked immediately. This same greedy approach applies to "minimum number of splits to make string value ≤ k" in various numerical contexts. Practice similar problems with different value functions.