leetcode.el icon indicating copy to clipboard operation
leetcode.el copied to clipboard

Use the leetcode assessment of test correctness

Open dpkatz opened this issue 1 year ago • 0 comments

The code currently decides whether or not the answer is the expected answer by comparing the code_answer and expected_code_answer output blocks in the response to see if they're the same. This can be an issue for problems where the output is a list but the problem specifies that the order doesn't matter. For instance, for problem 49 (Group Anagrams) the problem states that "You can return the answer in any order." However, running my solution to that problem gave:

FAIL:

Code Answer:
[["eat","tea","ate"],["tan","nat"],["bat"]]
[[""]]
[["a"]]

Expected Code Answer:
[["bat"],["nat","tan"],["ate","eat","tea"]]
[[""]]
[["a"]]

in the *leetcode-result-49* buffer. The problem here is that the we're not respecting the order-insensitivity of the answer the problem specifies.

Looking at the result data structure, we see that there is also a correct_answer field which is the Leetcode assessment of whether the answer was correct or not. For example, in the case shown above the "correct_answer" field is set to "true".

This change uses the "correct_answer" field to decide whether the test passed or failed, rather than comparing the output blocks directly.

Resolves #148

dpkatz avatar Apr 01 '25 19:04 dpkatz