Return true if the given string contains 1 or 3 ‘e’ chars. Otherwise return false.





Following are the test cases

Test cases Result Status
stringE(Hello) true OK
stringE(Heelele) false OK
stringE(Heelle) true OK

Java solution


package test;

public class Program16 {
	public static void main(String[] args) {
		Program16.stringE("Hello");
		Program16.stringE("Heelele");
		Program16.stringE("Heelle");
	}
	public static boolean stringE(String str) {
		char[] letters = str.toCharArray();
		int count = 0;
		for (int i = 0; i < letters.length; i++) {
			if (letters[i] == 'e') {
				count++;
			}
		}
		if (count == 1 || count == 3) {
			return true;
		}
		return false;
	}
}

Javascript solution


const stringE = (str) => {
    let count = 0;
    for (let i = 0; i < str.length; i++) {
        if (str[i] === 'e') {
            count++;
        }
    }
    if (count === 1 || count === 3) {
        return true;
    }
    return false;
}

console.log(stringE('Hello')); //true
console.log(stringE('Heelele')); //false
console.log(stringE('Heelle')); //true




Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply