Optional: Implement the count_rotations function using the generic binary_search function

Hi guys, I am trying to do the optional part of the assignment. I got an error as in the screen shot.
In practice, I define the condition function inside the generic count rotations function. The ‘hi’ variable is an argument in the generic binary_serach algo, which I supplied as len(nums)-1. However somehow the condition function can’t see it. Why is this?

Thanks a lot for your help.


Hey, I don’t remember the optional question so can I ask why you are defining the function in 2 parts? why not simply have the conditions in the same function?

As for your query, I think to access/call variables of other functions you would have to use the self keyword.
Which (what I think), would make the code a bit more complex.

1 Like

Hi utkarsh, thank you for your help. In the end I found the error, the variable shouldn’t be define as nums[hi].