Test cases Failed to pass

Can u tell me why Trie is not giving the correct answer for all the test cases or why my code is not giving the correct answer for all the test cases
"
import java.util.*;
public class STringWindow {
static int count = Integer.MAX_VALUE;

public class Node {
	char data;
	HashMap<Character, Node> children;
	boolean isTerminal;

	public Node(char data, boolean isTerminal) {
		this.data = data;
		this.isTerminal = isTerminal;
		this.children = new HashMap<>();
	}
}

private int numOfWords;
private Node root;

public STringWindow() {
	// TODO Auto-generated constructor stub
	this.root = new Node('\0', false);
	this.numOfWords = 0;
}

public void addWord(String word) {
	addWord(this.root, word);
}

private void addWord(Node parent, String word) {
	// TODO Auto-generated method stub
	if (word.length() == 0) {
		if (!parent.isTerminal) {
			parent.isTerminal = true;
			this.numOfWords++;
		}
		return;
	}
	char cc = word.charAt(0);
	String ros = word.substring(1);
	Node child = parent.children.get(cc);
	if (child == null) {
		child = new Node(cc, false);
		parent.children.put(cc, child);

	}
	addWord(child, ros);

}

public void display() {
	display(this.root, "");
}

private void display(Node parent, String ans) {
	if (parent.isTerminal) {
		System.out.println(ans.substring(1) + parent.data);

	}

	Set<Map.Entry<Character, Node>> entries = root.children.entrySet();
	for (Map.Entry<Character, Node> entry : entries) {
		display(entry.getValue(), ans + parent.data);
	}

}

public void stringwindow(String find) {
	String[] fans = { "" };
	stringwindow(this.root, find, "", fans);

	if (count == Integer.MAX_VALUE) {
		System.out.println("No string");
	} else {
		System.out.println(fans[0]);
	}
}

private void stringwindow(Node parent, String find, String ans, String[] fans) {
	// TODO Auto-generated method stub
	if (parent.isTerminal && find.length() != 0) {
		return;
	}
	if (find.length() == 0) {
		if (ans.length() < count) {
			fans[0] = ans;
			count = ans.length();
		}
		return;
	}

	Set<Map.Entry<Character, Node>> entries = parent.children.entrySet();
	for (Map.Entry<Character, Node> entry : entries) {
		char c = entry.getKey();
		if (c == find.charAt(0)) {
			String ros = find.substring(1);
			stringwindow(entry.getValue(), ros, ans + c, fans);
		} else {
			stringwindow(entry.getValue(), find, ans + c, fans);
		}

	}

}

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scn = new Scanner(System.in);

	STringWindow ts = new STringWindow();
	String str = scn.nextLine();
	String sub = scn.nextLine();
	String[] currencies = str.split(" ");
	for (int i = 0; i < currencies.length; i++) {
		ts.addWord(currencies[i]);
	}

	ts.stringwindow(sub);
}

}

"

@guptadev354,

Sample test case:
AabaA
aA
Correct answer:
Aa
Your answer:
AabaA

Suggested approach:

  1. First check if length of string is less than the length of given pattern, if yes then "no such window can exist ".
  2. Store the occurrence of characters of given pattern in a hashmap.
  3. Start matching the characters of pattern with the characters of string i.e. increment count if a character matches
  4. Check if (count == length of pattern ) this means a window is found
  5. If such window found, try to minimize it by removing extra characters from beginning of current window.
  6. Update min_length
  7. Print the minimum length window.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.