AlgoUniversity
  • Go Back
Discussion
Count Function :

Author

Ujjwal Srivastava

Difficulty Level : Easy

Submissions : 201

Asked In : saplabs

Marks :10

: 2 | : 0

Given a string $$$A$$$ consisting of $$$n$$$ lowercase English alphabets. Consider a function that takes a character as an argument and returns the $$$ASCII$$$ value of the character. For example $$$f(a)=97,f(z)=122$$$.

For each index $$$i (1 \le i \le n)$$$, determine the count of indices $$$j$$$ such that $$$j > i$$$ and $$$|f(Ai)-f(Aj)| \leq D.$$$

Here $$$|x|$$$ denotes the absolute value of $$$x.$$$

Return an array of $$$n$$$ integers, each of which denotes for each index $$$i (1 \le i \le n)$$$, the count of indices $$$j$$$ such that $$$j > i$$$ and $$$|f(Ai)-f(Aj)| \leq D.$$$

Input

The first line contains an integer $$$n$$$, denoting the length of the string. The second line contains the string $$$A$$$ consisting of $$$n$$$ lowercase English alphabets. The third line contains an integer $$$D$$$.$$$(1 \le n,D \le 10000)$$$

Output

For each index $$$i (1 \le i \le n)$$$, determine the count of indices $$$j$$$ such that $$$j > i$$$ and $$$|f(Ai)-f(Aj)| \leq D.$$$

Examples

Input
4
bbac
1
Output
3 2 0 0 
Input
5
zscda
6
Output
0 0 2 1 0 
Input
5
jsxhv
2
Output
1 0 1 0 0 

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.