RUNTIME ERROR! ---- BSTOPS

My code is giving RUNTIME ERROR (SIGSEGV) when i submit it.I don’t understand why this is happening. I have used binary trees here.
Here’s the problem :-BSTOPS Problem - CodeChef
You can also view my solution here :-CodeChef: Practical coding for everyone

Edit: Try again:

#define N (32<<1)
...
    char arr[N]={NULL};

The array you’re allocating can only hold 64 entries, so e.g. the testcase:

10
i 1
i 2
i 3
i 4
i 5
i 6
i 7
i 8
i 9
i 10

will result in an out-of-bounds access in ins.

[simon@simon-laptop][13:02:37]
[~/devel/hackerrank/otherpeoples]>echo "10
> i 1
> i 2
> i 3
> i 4
> i 5
> i 6
> i 7
> i 8
> i 9
> i 10
> " | ./a.out
1
3
7
15
31
63
vishal_10918-BSTOPS.cpp:6:16: runtime error: load of address 0x7ffc24786a8f with insufficient space for an object of type 'char'
0x7ffc24786a8f: note: pointer points here
 00 00 00 00 00  00 00 00 00 00 00 00 00  97 0b 06 e2 a2 7f 00 00  00 00 00 00 00 00 00 00  78 6b 78
             ^ 
127
vishal_10918-BSTOPS.cpp:12:11: runtime error: store to address 0x7ffc24786a8f with insufficient space for an object of type 'char'
0x7ffc24786a8f: note: pointer points here
 00 00 00 00 00  00 00 00 00 00 00 00 00  97 0b 06 e2 a2 7f 00 00  00 00 00 00 00 00 00 00  78 6b 78
             ^ 
vishal_10918-BSTOPS.cpp:7:20: runtime error: load of address 0x7ffc24786a8f with insufficient space for an object of type 'char'
0x7ffc24786a8f: note: pointer points here
 00 00 00 00 37  00 00 00 00 00 00 00 00  97 0b 06 e2 a2 7f 00 00  00 00 00 00 00 00 00 00  78 6b 78
             ^ 
255
511
1023
2 Likes

Yeah I got it. Thank you so much. :smiley:

1 Like

See here, and in particular the Codeforces blog linked from that post.

For this one, I used the -fsanitize=undefined gcc compiler flag.

3 Likes

Is there any way to debug my code on CodeChef IDE?

Dunno - I try to use the Codechef IDE as little as possible :slight_smile:

2 Likes

The new problem is tle i think it is due to creation of an array of a large size as big as 2^(32).
Can this be the proper reason?
If yes, then how can I create an array of such large size in less time?

Hint: There’s no need to create a large array at all :slight_smile:

2 Likes

But the position may vary from 1 to 2^(32) -1. :thinking:
Okay if I assume that this can be done within a smaller array, I should be using vectors probably.

Further hint: you don’t need any arrays at all - the question is about trees :slight_smile:

2 Likes

Okay I got it, I need to use structures!! :smiley:
actually I have not studied trees yet and I wanted to try this question without prior knowledge so I went with arrays.
But now I think I need to watch a binary tree tutorial.

1 Like

Yes I did!!, still a runtime error. Can you please tell me where am I going wrong on pointers??:pleading_face:

I’d recommend leaving this Problem - it seems pretty broken to me.

1 Like