AlgoUniversity
  • Go Back
Discussion
String Letter Search :

Author

Ayush Kumar Shaw

Difficulty Level : Easy

Submissions : 732

Asked In : Accenture

Marks :10

: 10 | : 0

You are given a string $$$s$$$ and a character $$$x$$$. Return the maximum distance between any two occurences of $$$x$$$ in the string $$$y$$$. The distance between $$$2$$$ occurences of a character is defined as the total number of distinct characters between them excluding white spaces and the character itself. Output $$$-1$$$ if the $$$x$$$ doesn't exist in the string $$$s$$$ or occurs only once.

The string $$$s$$$ consists only of lowercase latin letters and white spaces.

Input

The first line contains a string $$$s(1 \leq |s| \leq 10^6)$$$.

The second line contains a character $$$x$$$. It is guaranteed that $$$x$$$ is a lowercase latin letter.

Output

Output a single integer - the max distance between $$$2$$$ occurences of $$$x$$$ or $$$-1$$$ if it is not possible.

Example

Input
my name is granar
a
Output
7

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.