Question bank › Backtracking
Dsa Backtracking Medium

Prime-Sum Digit Partition

Given a string of digits and an integer K, partition the string into exactly K non-empty contiguous substrings such that the sum of the digits in each substring is a prime number. Print the substrings separated by spaces. If multiple solutions exist, print the lexicographically first one (treating the partition as a list of strings). If no such partition exists, print 'None'. Note: 1 is not a prime number. Example: Input: 2 1234 Output: 12 34 (Explanation: Sum of digits in '12' is 3, in '34' is 7. Both 3 and 7 are prime.)

Key concepts

backtrackingmathstring partitioning

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.