Partition a number into two divisible parts
Medium Accuracy: 58.36% Submissions: 531 Points: 4

Given a number (as string) and two integers a and b, divide the string in two non-empty parts such that the first part is divisible by a and the second part is divisible by b. In case multiple answers exist, return the string such that the first non-empty part has minimum length.


Example 1:

1200 4 3
12 00
12 is divisible by 4, and
00 is divisible by 3.


Example 2:

125 12 5
12 5
12 is divisible by 12, and 
5 is divisible by 5.


Your Task:

You don't need to read input or print anything. Your task is to complete the function stringPartition() which takes the string S and returns a string which will be in the form of first sub-string + " " (Single Space) + second sub-string. If not found return -1 as a string.


Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)





We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Partition a number into two divisible parts

Output Window