CodeChef IDE sucks

Codechef makes programming very challenging

One fine evening I was trying to attempt CodeChef Lunchtime Oct 2019. After grueling with pen & paper I decide to code on CodeChef’s IDE.

Question https://www.codechef.com/LTIME77B/problems/BOXGAM97
My code is as follows:

# cook your dish here
def flip(P):
    if P == 0:
        return 1 
    else:
        return 0

def rightOrLeft(box, P, pos, N):
    if P == 1:
        if pos == 0:
            return 1
        if box[pos - 1] < box[pos + 1]:
            pos -= 1 
        else:
            pos += 1
    
    else:
        if pos == N - 1:
            return N - 2
        if box[pos - 1] > box[pos + 1]:
            pos -= 1 
        else:
            pos += 1
            
    return pos
    
cases = int(input())

for cas in range(cases):
    #Code here
    N, K, P = map(int, input().split())
    
    box = list(map(int, input().split()))
    
    if P == 0:
        pos = box.index(max(box))
    elif P == 1:
        pos = box.index(min(box))
        
    P = flip(P)
    
    for b in box:
        pos = rightOrLeft(box, P, pos, N)
        P = flip(P)
            
    print(box[pos])

Codechef IDE produces error even for demo test case which is

2
4 3 0
4 1 9 5
4 3 1
4 1 9 5

Runs well in geeksforgeeks IDE
Proof : https://ide.geeksforgeeks.org/LV3Eg8xYqV

Same code on different platforms run differently. So, I tried to run it on my Desktop (Windows 10, Python 3.7.3) and it works like charm.
Observe the 9 & 1 in between the inputs. That is the required output for the test case.

C:\Users\pankaj.kum\Desktop>python try.py
2
4 3 0
4 1 9 5
9
4 3 1
4 1 9 5
1

So, to conclude CodeChef has a quite jerky system within. They need to listen to the abuses seriously. Otherwise it will be too late.

P.S GeeksForGeeks, I love you!

Python for competitive programming

Last night I was participating in CodeChef October Cookoff for the first time. It was a good experience even though I could solve one problem completely & two others partially attempted out of total five.

So, there’s a language debate over which should be better for competitive programming. I natively speak in python though I started off with C/C++ family. So, let’s see some comparison over a brute force solution to a problem written in Python (A slow language) and C++ (A fast language).

Python takes > 5.01 seconds (The limit for python on CodeChef is 5.01s).

cookpy

Now, Even C++ fails to nail the brute force approach (The limit for C++ on CodeChef is 1.01s).

cookcpp

So, the crux of the story is…

Concentrate on the correct Logic / Algorithm to solve rather than a certain specific language.

Though this is for the beginners & of course data structure are heavy with Python but for your own sake learn better algorithms each day.

Design a site like this with WordPress.com
Get started