HackerRank : 101 Hack 41- Lecture Notes

By | September 20, 2016

Alex has a habit of falling asleep during lectures! In order to complete the day’s homework, he must determine if he has any friends that stayed awake so he can borrow their notes.

There are other students in Alex’s class, and each student has a distinct ID number from to . You are given a string, , of binary characters where the character denotes whether the student slept during the lecture or not. If the character is a , then the student stayed awake and took notes; otherwise, the character is a which indicates the student fell asleep and did not take notes.

Alex has friends in his class and you are given a list of integers corresponding to their respective ID numbers. If Alex can borrow the lecture notes from one of his friends, print YES; otherwise, print NO.

Input Format

The first line contains two space-separated integers denoting the respective values of (the number of students in Alex’s class) and (Alex’s number of friends in the class).
The second line contains a single binary string (i.e., ‘s and ‘s) of length . If the character is a , then Alex can’t get notes from them; otherwise, it’s a , indicating the student took lecture notes.
The next line contains distinct space-separated integers where each integer denotes the ID number of one of Alex’s friends.


Output Format

Print YES on a new line if Alex can get the lecture notes from one of his friends; otherwise, print NO.

Sample Input

3 2
1 3
Sample Output


There are other students in the class, and of them are Alex’s friends. Students and fell asleep, but student stayed awake. Alex is only friends with students and and, as they both fell asleep during the lecture, Alex cannot get notes from them. Thus, we print NO as our answer.


package hack41;

import java.util.Scanner;

public class LectureNotes {

public static void main(String[] args) {

Scanner scan= new Scanner(System.in);

int n= scan.nextInt();
int k = scan.nextInt();

String str=scan.nextLine();
char attendance[]=str.toCharArray();

String frnds=scan.nextLine();

String frndsFinal[]=frnds.split(” “);

/* for(int i=0;i<frndsFinal.length;i++)
int borrrow=0;
for(int j=0;j<frndsFinal.length;j++)
int frndId=Integer.parseInt(frndsFinal[j]);