LeetCode Online Judge Bug.


  • 0
    U

    My code runs when I click run code but gives run time error when I click submit.

    I have printed all memory access points to make sure it is never going out of bound. (run code stdout is shown after the code)
    It is failing on input:

    "zechiwcmjktroasetkzxlxpdibkeiqdhuhqfdsrmfmfvny"
    "ziiahux"
    

    Here is the code:

    #define i(c) c-'a'
    class Solution {
    public:
        string minWindow(string s, string t) {
            //unordered_map<char,int> m,m2;
            int last_index=0,start=-1,end,min=10000000;
            int count=0;
            int count2=0;
            int *m = (int*)calloc(26,sizeof(int)),*m2 = (int*)calloc(26,sizeof(int));
            
            for(int i=0;i<t.size();i++){
                m[i(t[i])]--;
                if(m[i(t[i])]==-1)
                    count++;
                cout<<i(t[i])<<endl;
            }
            
            for(int i=0;i<s.size();i++){
                cout<<i(s[i])<<endl;
                if(m[i(s[i])]!=0){
                    
                    m2[i(s[i])]++;
                    if( m2[i(s[i])] == (-1)*m[i(s[i])] ){
                        m[i(s[i])]*=-1;
                        count2++;
                    }
                    if(count==count2){
                        cout<<i(s[last_index])<<endl;
                        while( m[i(s[last_index])]==0 || m2[i(s[last_index])] > m[i(s[last_index])] ) {
                            m2[i(s[last_index])]--;
                            last_index++;
                        }
                        //cout<<s.substr(last_index,i-last_index+1)<<" "<<i-last_index<<endl;
                        if(i-last_index<min){
                            start=last_index;
                            end=i;
                            min=i-last_index;
                        }
                    }
                    
                }
            }
            
            if(count2==count)
                return s.substr(start,end-start+1);
            else return "";
        }
    };
    

    Here is the output for run code:

    Run Code Result:
    Your input
    
    "zechiwcmjktroasetkzxlxpdibkeiqdhuhqfdsrmfmfvny"
    "ziiahux"
    
    Your stdout
    
    25
    8
    8
    0
    7
    20
    23
    25
    4
    2
    7
    8
    22
    2
    12
    9
    10
    19
    17
    14
    0
    18
    4
    19
    10
    25
    23
    11
    23
    15
    3
    8
    1
    10
    4
    8
    16
    3
    7
    20
    25
    7
    0
    16
    5
    3
    18
    17
    12
    5
    12
    5
    21
    13
    24
    
    Your answer
    
    "asetkzxlxpdibkeiqdhu"
    
    Expected answer
    
    "asetkzxlxpdibkeiqdhu"
    
    Runtime: 0 ms

  • 0
    S

    normally, oj doesn't allow 'cout' and gives an error. Do you have couts in the code you submit?


  • 0
    U

    No cout were there in the submit code.


  • 0

    Using coutis not only allowed but even supported (the OJ shows you your output (except in some cases where something goes wrong)).


  • 0

    The OJ's bug is that it shows you the wrong test case, not the one you failed.

    Your bug is that you assume that the strings only consist of lower case ASCII letters a-z.


  • 0
    S

    thanks, nice to know! sorry to confuse, I believed it was not supported.


  • 0

    @samoshka Yeah, it's relatively new, was added only 2-3 months ago or so.


  • 0
    U

    Not working even if I assume that the characters can be upper case.


  • 0

    You're still only covering letters, I assume? Not other characters like punctuation?


  • 0
    U

    Got Accepted. I wasn't handling the upper case properly.

    Thanks for your help Stefan.


Log in to reply
 

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