Pokemon Pikachu

Pikachu is a well-known character in the Pokemon anime series. Pikachu can speak, but only 3 syllables: “pi”, “ka”, and “chu”. Therefore Pikachu can only pronounce strings that can be created as a concatenation of one or more syllables he can pronounce. For example, he can pronounce the words “pikapi” and “pikachu”.
1)i/p=”pikapi”    Returns: “YES”   = >   “pikapi” = “pi” + “ka” + “pi”

2)i/p=”pipikachu”    Returns: “YES”    =>   “pipikachu” = “pi” + “pi” + “ka” + “chu”

3)i/p=”pikaqiu”      Returns: “NO”    => since ‘q’ does not appear in “pi”, “ka”, or “chu”.

4)i/p=”daynight”     Returns: “NO”

5)i/p=”piika”  Returns: “NO”

public class PikachuEasy {
    public String check(String word) {
        String ans = "YES";
        word = word.replace("pi", " ");
        word = word.replace("ka", " ");
        word = word.replace("chu", " ");
        if((word.trim()).length()>0) ans = "NO";

        //simple approach
        //return word.matches("((pi)|(ka)|(chu))*") ? "YES": "NO";
        return ans;

    public static void main(String[] args) {
        PikachuEasy pe = new PikachuEasy();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: