Need help solving Huffman decoding

I'm given a list of Huffman codes as an input. Each element in the list is separated by a tab character (ex. a [tab] 100100):

a   100100
b   100101
c   110001
d   100000
[newline]   111111
p   111110
q   000001

as well as an encoded string 111110000001100100111111100101110001111110.

I am being asked to return the correct string from the code. In this case it would be:


since p = 111110, q = 000001 and so on.

I've tried submitting my code and the autograder works for 2 cases but doesn't work for the hidden cases.

Would anyone be able to tell me what I might be doing wrong?

static String decode(List<String> codes, String encoded) {
String s = "";
String ans = "";  
String[] splited = new String[2];

Hashtable<String, String> numbers = new Hashtable<String, String>();

    for(int i = 0; i < codes.size(); i++){
     splited = codes.get(i).split("\t");


    for(int j = 0; j < encoded.length(); j++){
      s = s+encoded.charAt(j); 
        if(s.equals("111111") ){
            ans = ans +"\n";
        } else{
       ans = ans + numbers.get(s);} 
       s = ""; 

    return ans;

Just to clarify, I am using the first for loop to split each letter from the number code by the tab and putting it into a temp array. Then I am adding these 2 values to a Hashtable (letter, code).

In the second for loop I am iterating each character in the decoded string until the string matches on of the codes, then adding the letter to an answer string and returning that answer string.