Can not get a very long string input that fail my submission.


  • 0
    I

    My submission got "Wrong Answer". But the input string is so long that it can not be displayed completely in the result. Can anybody or leetcode admin help me to have the very long inputs that failed my submission?

    public class Solution {
    public String minWindow(String S, String T) {

        if (T == null || T.length() == 0) return new String("");
        
        Map<Character, Integer> expected = new HashMap<Character, Integer>();
        
        Map<Character, Integer> collected = new HashMap<Character, Integer>();
        
        for(int i = 0; i < T.length(); i++){
            if (!expected.containsKey(T.charAt(i))){
                expected.put(T.charAt(i), 0);
                collected.put(T.charAt(i), 0);
            }
            expected.put(T.charAt(i), expected.get(T.charAt(i))+1);
        }
        
        int start=0, end=0;
        
        int counter = 0; int minWindow = Integer.MAX_VALUE;
        
        String result = new String("");
        
        while (true) {
           boolean find = false;
           while( end < S.length()){
                char ch = S.charAt(end);
                end++;
                if (!expected.containsKey(ch)){
                    continue;
                }
                collected.put(ch, collected.get(ch)+1);
                if (collected.get(ch) == expected.get(ch)){
                    counter++;
                    if (counter == expected.keySet().size()) {
                        find = true;
                        break;
                    }
                }
            }
            
            if (!find){
                break;
            }
            
            while(start < end) {
                char ch = S.charAt(start);
                start++;
                if (!collected.containsKey(ch)) {
                    continue;
                }
                collected.put(ch, collected.get(ch)-1);
                if (collected.get(ch) < expected.get(ch)) {
                    counter--;
                    break;
                }
            }
            
            String substring = S.substring(start-1, end);
            if (substring.length() <= minWindow) {
                minWindow = substring.length();
                result = substring;
            }
        }
        
        return result;
    }
    

    }


Log in to reply
 

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