Hackerearth May circuit 2019

In the problem Restoring trees(set 2 problem 1) I am getting SIGSEGV runtime error in 4 test cases out of 41 test cases and getting 88/100. As contest has ended can somebody help me.I have tried it for many hours but still not getting 100.

submission and code link:-

problem statement link:-

@vijju123 @anon55659401 @samarthtandon

1 Like

is the right person to be asked.


Will have to write a code first to unlock it :slight_smile:

1 Like

should I copy my code over here??It is in python

HackerEarth has very less stack(implicit) size for Java and probably for Python too.
I checked it a few days back its almost only 2e4 for Java and I have heard Python users have faced similar problem in past.

but some(very few) have got 100 in this problem in python

Can you share one recursive dfs-based python solution ?

Most of them are iterative dfs.

I am using recursion and code is of O(n) complexity.

import sys
def trav(st,end,par):
global s,ss
while ind<end:
del s[ind]
if node[1]-ind==1:

for i,j in zip(st,end):
if i==0 and j==n:
del st,end
for i in range(n):
print(ss[i],end=" ")

My approach is right as I am getting no WA but RE(SIGSEGV) on 4 test cases.Like most take test cases took more than 1 second to solve but these with RE stop before 0.5 second only. Can you tell why SIGSEGV occurs and why is it occuring in my case

hello, I’m able to solve this with full 100pts…Yes, there is some error in the test cases I don’t know because when I submit the code in c++14 then it got AC and when I submit the same code with python3, Java8, C it got RE in 2-3 test cases…

BTW the question was quite easy …One simple recursive dfs will able to give to AC in just O(N) time complexity…

you can check my solution here…


Well I mentioned the reason -

Your code is OK.

Its because of stack Overflow Error.

I think this contest is quite good for me …I’m able to solve all 8 questions this time (only 1 question with 52pts)

but the explanation of problem statements was terrible this time…every question have some amount of ambiguity in the statements…

1 Like

There is no error in test cases.

yes, but I don’t know why it fails on other programming language other than c++14

even in C language it was failed and got RE…(don’t know the reason till now!!)

I don’t know about C but for Java and Python, I’m preety sure.

1 Like

I think you can Unlock any problem without solving it…but it will cost to detect all your marks from that question

here is my recursive python 3 code…but RE in 5 test cases:


Yup, this is what I mean to say. Try with iterative DFS and it will run fine with all AC.


but I don’t think Iterative solution to the problem of this type was good practice…

I think HackerEarth need to resolve this problem…

BTW thanks…I never expect these type of errors…

Ikr… I would rather solve it before unlocking… will get back here if I get any other reason for runtime error