why am i getting 3 wrong answers on submission
https://ide.codingblocks.com/s/46091
Count bst subtrees that lie in given range .,.,
Hey Jai, as your code is recursive don’t declare the variables i, j and cnt globally if you want to you can pass them by reference. One more thing, in your code you are using i and j to represent the range at the current stage, so there is no point to pass these variables globally.
my code works for the given sample test case but on submission am getting 3 wrong test cases
am not able to understand my mistake
PLEASE HELP
my code
https://ide.codingblocks.com/s/46091
qn link
https://hack.codingblocks.com/contests/c/511/1601
please reply ,.
Hi Jai,
- You should avoid declaring global variables. You can rather pass them as parameters in function calls.
- For the call of left subtree in the insert function, the indexes should be s and mid-1. Similarly, for right subtree, the indexes should be mid+1 and e because the array is sorted in ascending order.
I’ve made few changes to your code and now it’s working. Check it out and let me know in case of any doubts.
https://ide.codingblocks.com/s/49521
thanks a lot for the help