Test 32 is giving wrong answer on Onine Tester but gives correct on my local

  • 0

    Does anyone know why online tester is making test case 32 fail even though it works fine on my loca;

    Here is the code

    public class Solution {
        public String getHint(String secret, String guess) {
        	char[] secretChar = secret.toCharArray();
        	char[] guessChar = guess.toCharArray();
        	Set <String>secretSet = new HashSet<String>();
        	for(int i=0;i<secret.length();i++) {
        	// now since length of both arrays are equal we will first search of characater
        	int bullCounter=0;
        	int cowCounter=0;
        	for(int i=0;i<guessChar.length-1;i++) {
        		if(secretChar[i]==guessChar[i]) {
        			if(secretSet.contains(String.valueOf(guessChar[i]))) {
        	String result = bullCounter+"A"+cowCounter+"B";
        	return result;

  • 0

    I think it would help if you shared the failng test case. Test cases are not public afaik, so we can't look up by number.

  • 0

    You should use Set<Character> that would make the code cleaner. (char <-> Character conversion is automatic in Java: auto-boxing)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.