All Tracks Basic Programming Implementation Basics of Implementation Problem

Rhezo and character frequency
Tag(s):

Basic Programming, Easy

Problem
Editorial
Analytics

Rhezo got a string $$S$$, a character $$C$$ and an integer $$P$$ as a birthday gift from his best friend JK.

He got curious about the gift and started analysing it. He found out that the maximum frequency of character $$C$$ over all the $$P$$ length substrings of $$S$$ is equal to some integer $$Z$$.

He doesn't know programming, so asks you to find the largest position, where, if we insert some character after that position, the maximum frequency of $$C$$ over all the $$P$$ length substrings becomes $$Z + 1$$. If there is no such position, output $$-1$$.

If the answer is the position before the first character, output $$0$$.

Input:

First line of the input contains a string $$S$$.
Second line of the input contains the character $$C$$.
Next and the last line contains a single integer $$P$$.

Output:

Print an answer in a separate line.

Constraints:

  • $$1 \le |S| \le 10^3$$
  • $$1 \le P \le |S|$$
  • $$S$$ consists of lowercase alphabetic characters
  • $$C$$ is any lowercase alphabetic character

SAMPLE INPUT
asdnajsdnasj
d
3
SAMPLE OUTPUT
9
Explanation

Inserting a character after $$9^{th}$$ position, gives a sub string of length $$3$$ in which frequency of $$'d'$$ is $$2$$.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

December Easy '16

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications