Studying Alphabet Codechef Solution

Hello Programmers In this post, you will know how to solve the Studying Alphabet Codechef Solution. The Problem Code: ALPHABET

Studying Alphabet Codechef Solution
Studying Alphabet Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.


Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.

He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows.

Now Chef is curious about which words his brother will be able to read, and which are not. Please help him!


The first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can read. Every letter will appear in S no more than once.

The second line of the input contains an integer N denoting the number of words in the book.

Each of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word in the book.


For each of the words, output “Yes” (without quotes) in case Jeff can read it, and “No” (without quotes) otherwise.


  • 1 ≤ |S| ≤ 26
  • 1 ≤ N ≤ 1000
  • 1 ≤ |Wi| ≤ 12
  • Each letter will appear in S no more than once.
  • S, Wi consist only of lowercase Latin letters.


  • Subtask #1 (31 point)|S| = 1, i.e. Jeff knows only one letter.
  • Subtask #2 (69 point) : no additional constraints

Sample Input 1 


Sample Output 1 



The first word can be read.

The second word contains the letters d, o and g that aren’t known by Jeff.

Studying Alphabet CodeChef Solution in JAVA

import java.util.Scanner;
import java.util.Set;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(;
		String S =;
		Set<Integer> knownLetters = S.chars().boxed().collect(Collectors.toSet());
		int N = sc.nextInt();
		for (int tc = 0; tc < N; tc++) {
			String W =;
			System.out.println(solve(knownLetters, W) ? "Yes" : "No");
	static boolean solve(Set<Integer> knownLetters, String W) {
		return W.chars().allMatch(ch -> knownLetters.contains(ch));

Disclaimer: The above Problem (Studying Alphabet) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Task for Alexey Codechef Solution

Leave a Reply

Your email address will not be published. Required fields are marked *