First, let me thank LeetCode for organizing these monthly challanges since APRIL 👍👍. These challanges have helped a lot of procrastinators like me to do alteast one thing consistantly , CODE
Now, about me, I code in JAVASCRIPT. I know, not very popular for C.P, but man I love it..😍
(PLEASE ! Give this a read even if you code in different languages, as the problem can be common)
These past few monts while coding on the platform, I have noticed,
Some unusual behaviour, by the online judging system.
If I submit the same code multiple times, the time to run them should be consistent, right ? I mean, I haven't changed a single line of code man.
But no, each time I submit, the submission time for the same code is different, and heck It is significantly different like 20-30 ms difference.
First I thought this was because, the judge being online the sumission could depend on the client internet speed, so I didn't gave it too much of a thinking.
So what story over, solution found, right? WRONG XXXX
Bare with me, for a minute and
Let's, talk about todays JULY challange Problem
DELETE node in Linked List -> https://leetcode.com/explore/challenge/card/june-leetcoding-challenge/539/week-1-june-1st-june-7th/3348/
(GIVE THE PROBLEM STATEMENT A READ AND COME BACK)
The fastest solution I can think of is as follows
Replace the current node Value with the next node's value
make the pointer of the current node point to the next of the next node;
var deleteNode = function(node) {
node.val = node.next.val;
node.next = node.next.next;
};OK DONE !
Just two plane and simple steps ,O(1) -> time .
O(1)-> space.
clean,FASTEST and simple !
But Naa! Aah!, not so fast!
What if I told you, this solution only have runtime better then 30% of submission?(the run time according to the online judge is 76ms)
whatttttttttttttt? How is this even possible?
Infact, according to the drunk online judge, and the Normally Distributed runtime graph, this below is the fastest of the bunch, with 44ms time. period.
var deleteNode = function(node) {
if(node.next!==null){
node.val=node.next.val
node.next=node.next.next
}
};
Wait what? They are the same right?
Damn right they are,
then how is the judging system handling the task so as to run the same code in two very different runtimes??
Who knows? Definitely I don't.
I just want to convey this message to the administrators, to look into this, because many of the participantsdishe will be disheartened, and will feel discouraged if they work for some difficult problem for hr's and they couldn't even have better runtime then even 50%,
If any of you are facing the same issue with different languages, Please write in the comment box, so the administratos could know and solve the issue?