educative.io

Find kth max in BST: Recursive Implementation bug?

The recursive implementation does not work unless I specifically name my global variable “counter”, as it is in the solution. If I change the variable name to other names such as “count”, it no longer works. Is there any reason why?

1 Like

Figured out why, using global variables was a bad idea, which was why I was skeptical of the solution in the first place. I used a mutable object to store my count and current_max.


Course: https://www.educative.io/courses/data-structures-in-python
Lesson: Educative: Interactive Courses for Software Developers

Same case with me @Rika, could you please comment on this solution as well : IMHO some redundant variables and logic in Recursion solution

I think that solution is easier to understand, and may be removes redundant logic from original solution.


Course: https://www.educative.io/collection/5642554087309312/5634727314718720
Lesson: https://www.educative.io/collection/page/5642554087309312/5634727314718720/5722608653828096