Thursday, 18 May 2017

CodeFights does not evaluate JavaScript correctly

I'm looking at a very strange situation, I have two solutions for the reverseParentheses problem in CodeFights, but neither of them are accepted. I tested both solutions locally and they both pass.

Version 1:

Here is my source code and tests for the first version: https://repl.it/IFIp

When I run it on CodeFights, it shows that my solution fails on test 1:

1/7
Execution time limit exceeded on test 2: Program exceeded the execution time limit. Make sure that it completes execution in a few seconds for any possible input.

Version 2:

Here is my source code and tests for the second version: https://repl.it/IFIU/1

When I run it on CodeFights, it shows that my solution fails on test 2:

Input:
s: "a(bcdefghijkl(mno)p)q"
Output:
"a(bcdefghijklpmnq"
Expected Output:
"apmnolkjihgfedcbq"
Console Output:
13
13

Note that in CodeFights I'm logging the index of the left parentheses, just to debug what's happening. Interestingly, the left index doesn't change (thus the two 13's in the console output):

const l = p.pop();
console.log(l);
const r = s.indexOf(')', l);

Question

When I run my solutions locally or in repl.it, they pass with flying colors. However, CodeFights gives me an error in both situation. And the results are quite strange (especially in the second case, where the index of the left parentheses never changes). Is there a problem with my solution or does this seem like a bug in CodeFights?



via Lirik

No comments:

Post a Comment