Solution is being submitted to the wrong problem.
I have been trying to submit solutions but they keep getting submitted to the wrong problem/contest. Take an example using the snippet below. This code is supposed to be submitted to the walking-robot-simulation-ii problem which is questionId, 2069. But for some reason, it is always submitted to a different problem: kth-smallest-subarray-sum. I verified this by checking the latest submission on my submissions on the leetcode website. I have tried this on other problems as well and it get it right on some occasions e.g."two sum" and fail multiple times on others. What could be the reason and can you reproduce this on your side?
import os
import leetcode
from leetcode.api_client import ApiClient
from leetcode.configuration import Configuration
configuration = Configuration()
leetcode_session = os.getenv("LEETCODE_SESSION_ID")
csrf_token = os.getenv("LEETCODE_CSRF_TOKEN")
configuration.api_key["x-csrftoken"] = csrf_token
configuration.api_key["csrftoken"] = csrf_token
configuration.api_key["LEETCODE_SESSION"] = leetcode_session
configuration.api_key["Referer"] = "https://leetcode.com"
configuration.debug = False
configuration.api_key_prefix["Authorization"] = "Bearer"
code = """
from typing import List, Tuple
class Robot:
def __init__(self, width: int, height: int):
self.pos: List[Tuple[List[int], str]] = []
self.pos.append(([0, 0], "South"))
for i in range(1, width):
self.pos.append(([i, 0], "East"))
for j in range(1, height):
self.pos.append(([width - 1, j], "North"))
for i in range(width - 2, -1, -1):
self.pos.append(([i, height - 1], "West"))
for j in range(height - 2, 0, -1):
self.pos.append(([0, j], "South"))
self.isOrigin: bool = True
self.i: int = 0
def step(self, num: int) -> None:
self.isOrigin = False
self.i = (self.i + num) % len(self.pos)
def getPos(self) -> List[int]:
return self.pos[self.i][0]
def getDir(self) -> str:
return "East" if self.isOrigin else self.pos[self.i][1]
"""
submission = leetcode.Submission(
typed_code=code,
judge_type="large",
question_id=2069,
test_mode=False,
lang="python",
)
api_instance = leetcode.DefaultApi(ApiClient(configuration))
submission_id = api_instance.problems_problem_submit_post(
problem="walking-robot-simulation-ii", body=submission
)
print(submission_id)
Additionally, when you try to get the result from the submission_result = api_instance.submissions_detail_id_check_get(id=submission_id), you will get an error.
After investigating the graph ql params in the body, I discovered I was confusing the questionFrontEndId and the questionId. What I was passing to question_id was the questionFrontEndId.
I retrieved the correct question_id from viewing the page source in the browser. For the code snippet above, the questionId is 2178 and the questionFrontEndId is 2069.
I would suggest implementing a method to get the question_id from using the problem-slug. A simple get request to the url returns both the question_id and the questionFrontEndId. In a few of the problems, both the question_id and the questionFrontEndId are the same, but this is not the case for a large number of the leetcode problems.
Another solution would be simply allowing users to set questionFrontEndId which is always easily visible next to the leet code problem's title on the website.
Hey @jpangas. Thanks for the detailed report and your feedback. I'll try to take a look at it this weekend, need to refresh how it works in my head first