Different run time with same code?


  • 0
    W

    Recently I've found that subimissions with same code won't get same result. In fact, it varies a lot. First it beats 2.3 percents, then it could beats 92 percents. I don't think it's a good thing. I can't figure out my code is whether good or not. Anybody know why?


  • 0

    So when your code is run the second time, you expect the server to be in the exact same state as the first time?

    Which problem was it, which language did you use, and what were the two times?


  • 0
    W
    This post is deleted!

  • 0
    W

    @StefanPochmann power of four, C++, 4ms and 8ms, I may get wrong beats percents, is it normal?


  • 0

    @wr_bupt That seems odd. Are you sure it's that problem, C++, and 2.3% and 92%? I looked at some of my submissions with 8ms and 4ms, and I'm told I beat 13.80% and 83.51%. And I think you should get the same percentages.


  • 0

    @wr_bupt Yes indeed, sometimes the fluctuation is too much. @administrators Isn't it? The isolation is not handled properly in the backend perhaps.


  • 0

    @LHearen Please define "too much", as it is subjective. What was mentioned by @wr_bupt 4ms and 8ms is insignificant. However, the runtime distribution graph should not reflect a jump from 2% to 90+% within this small change. We'll refine on a displaying a better graph in the future.


  • 0

    @1337c0d3r Once, of course not often, I met quite the same case jumping too much from <10% to >80%.


  • 0

    @LHearen What you mean <10% to >80%? Please give concrete runtime numbers. As mentioned by @wr_bupt it is possible to jump from <10% percentile to >80% percentile, due to majority of submissions are within the 4ms-8ms range.


  • 0
    W

    @StefanPochmann Sorry, I remembered the wrong percent. But it do vary a lot, and what makes me surprised is that the run time just distribute at 4ms and 8 ms. Run time between 4ms and 8ms is just about 1 percent, that is far from evenly distributed. It appears like two different code with different efficiency rather than the state of machine, which I think is a random factor.


  • 0
    K

    @1337c0d3r Submitting LRU problem twice with the same code also reveals widely varying results - once 159 ms and once 92 ms.


  • 0
    C

    I ran the exact same Java code on two different days.

    1st submission: 8ms / "Beats 89.18% of submissions"
    2nd submission: 11 ms / "Beats 31.99% of submissions"

    Problem: https://leetcode.com/problems/valid-parentheses/description/

    Code:

    class Solution {
        public boolean isValid(String s) {
            if(s.length() %2 != 0) {
                return false;
            }
            LinkedList<Character> stack = new LinkedList<>();
            String openBrackets = "[({";
            String closeBrackets = "])}";
            int len = s.length();
    
            for(int i=0; i<len; i++) {
                char c = s.charAt(i);
                int j = openBrackets.indexOf(c);
                if(j >= 0) {
                    stack.push(closeBrackets.charAt(j));
                } else if (stack.isEmpty() || c != stack.pop()) {
                    return false;
                }
            }
            return stack.isEmpty();
        }
    }
    

Log in to reply
 

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