#K6741. Reorder String with Minimum Distance Constraint
Reorder String with Minimum Distance Constraint
Reorder String with Minimum Distance Constraint
Given a string ( s ) and an integer ( d ), your task is to reorder the characters in ( s ) such that any two identical characters are at least ( d ) positions apart. In other words, for any two indices ( i ) and ( j ) where ( s[i] = s[j] ) and ( i < j ), the condition [ j - i \ge d ] must hold. If there is no possible reordering that satisfies the condition, output an empty string.
inputFormat
The input is provided via standard input (stdin) and consists of two lines. The first line contains the string ( s ) and the second line contains the integer ( d ).
outputFormat
Output a single line to standard output (stdout) with the reordered string if a valid reordering exists; otherwise, output an empty string.## sample
aabbcc
3
abcabc