Valid partitions

4.4

14 votes
Algorithms, Basics of String Manipulation, Math Basic, Modulus Arithmetic, Math, Number Theory
Problem

You are given a string S and an integer K. Print the valid partition of the stringA valid partition for a provided S and K satisfies the following properties:

  • There exist strings s1,s2,...,sm where mK such that s1+s2.....+sm=S where + is the concatenation operator for strings.
  •  If  1im1, then length(si)=K.
  •  If  i=m, then K1length(si)K.

If a valid partition is not possible, then print -1.

Print the strings s1,s2...,sm in the partitions that are separated by ''.

Input format

  • First line: t denoting the number of test cases
  • Next t lines: Space-separated string S and an integer K

Output format

For each test case, print a single line containing the valid partition.

Constraints

1t10

2|S|1000 where |S| is the length of string

1K30

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

1) Output satisfies valid partition properties for m = 3.

2) Output satisfies valid partition properties for m = 3.

3) No valid partition is possible.Please note that "dsda-svvc-jkx" is not a valid partition because there needs to be at least K groups

Editor Image

?