This was the easiest problem of the contest. All one had to was to move over all characters is S and check if they were present in J as well. Checking could be done either by iterating over all character of J which takes time O(|J|) or by keeping an array/hashset for O(1) look up.
The reason that the error occurs is that the end of string is taken up by position c, so there is nothing to denote end of line or end of string, and hence it continues taking the other “aaaaaa…” as input of string 1.
This results in string 2 being an empty string, and for it the condition is always true.
Its an abnormal behaviour, and hence 1 extra character is always recommended.
(Tested code by asking it to print je…je and got the chars of next line in it. Hence the above theory)
public static void main(String args)
Scanner sc = new Scanner(System.in);
tc = sc.nextInt();
int count = new int[tc];
StringBuffer jewels = new StringBuffer(sc.next());
StringBuffer stones = new StringBuffer(sc.next());
Its actually because of how the code is pasted here by him. I had to do corrections to resume checking…you can say I got experience of this now XD (since its a problem with >75% of codes copy pasted here)
If anyone who doesn’t know much about hashset or any data structure , u can go do this ques by using simple brute force .U can go through my code. https://www.codechef.com/viewsolution/15487815
If u have any issue feel free to share.