Also, if you really are using leetcode to land a job, a programmers job also means a programmer must be able to debug the code that they write. I took your code, added the test case, and ran it locally, and instantly the error showed up at line 28 (I used Visual Studio). These are the skills necessary to be a programmer, not only coding, but also debugging. —
PaulMcKenzie 1 min ago