#K7541. Partition String into Distinct Substrings
Partition String into Distinct Substrings
Partition String into Distinct Substrings
Given a string s
and an integer k
, determine whether it is possible to partition s
into k non-empty, distinct substrings. In other words, you need to decide if one can divide the string into k parts (each part is a contiguous segment) such that no two parts are equal.
Let \( N = |s| \) be the length of the string and \( d \) be the number of distinct characters in s
. A necessary condition for such a partition is that \( k \le N \) and \( k \le d \). Print True
if such a partition exists, and False
otherwise.
inputFormat
The input is given via standard input in the following format:
s k
Where:
s
is a non-empty string.k
is an integer denoting the number of partitions required.
outputFormat
Output a single line to standard output: True
if s
can be partitioned into k distinct non-empty substrings, otherwise False
.
abcdak
4
True
</p>