Iterative solution

Let’s use stack implicitly:

def is_bst(node):
  cv = None
  stack = []
  while node or stack:
    if node:
      node = node.left
      node = stack.pop()
      if cv is not None and < cv:
        return False
      cv =
      node = node.right

  return True

Hi @Vladimir_Ryabtsev,

Thank you so much for reaching out to us.

Yes, we can use a solution with a loop that involves another data structure Stack, but our Stack is automatically managed by the OS with the recursive solution. You can use either of the solutions if there isn’t any restriction.

If you have any other queries, then please do let us know. Thank you.