Bob and his special string
Practice
4 (5 votes)
Binary search
Algorithms
Problem
85% Success 1006 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bob is very fond of strings so he is creating a new type of string. Help him in creating his new special string.

You are given a string \(s\) of length \(|s|\) and an integer \(n\). Now, you are required to find a string \(str\) of length at most \(n\) such that if you add this string \(x\) number of times (\(str+str+....x\ times\)) let us say it is \(xstr\), then the frequency of each character in \(xstr\) string should be greater than or equal to the frequency of the same character in the string \(s\). \(xstr\) should cover all the characters of string \(s\).

Help Bob in finding the minimum possible value of \(x\).

Input format

  • The first line contains an integer \(n\) representing the maximum length of string that Bob can write.
  • The second line contains a string \(s\) representing the given string.

Output format

Print an integer denoting the minimum possible value of \(x\).

Constraints
\(2 \le n \le 10^5\)
\(1\le|s|\le 10^5\)

where \(s\) only contains lowercase letters, that is, \(a-z\)
The total number of distinct characters in \(s\) is always less than or equal to \(n\).

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:30
55 votes
Tags:
ApprovedBinary SearchEasyGreedy AlgorithmsReadySorting
Points:30
20 votes
Tags:
Binary SearchEasySearching
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady