Valid partitions
Practice
4.4 (14 votes)
Algorithms
Basics of string manipulation
Math basic
Modulus arithmetic
Math
Number theory
Problem
84% Success 4337 Attempts 10 Points 5s Time Limit 256MB Memory 1024 KB Max Code

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 \(s_1,s_2, ...,s_m\) where \(m \geq K\) such that \(s_1+s_2.....+s_m = S\) where \(+\) is the concatenation operator for strings.
  •  If  \(1 \leq i \leq m-1\), then \(length(s_i) = K \).
  •  If  \( i = m\), then \(K-1 \leq length(s_i) \leq K \).

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

Print the strings \(s_1,s_2...,s_m\) 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

\(1 \leq t \leq 10\)

\(2 \leq |S| \leq 1000 \) where \(|S|\) is the length of string

\(1 \leq K \leq 30\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
3 votes
Tags:
Very-Easy
Points:10
57 votes
Tags:
MathematicsModulus ArithmeticMathNumber Theory
Points:10
2 votes
Tags:
Very-Easy