how can I translate this to Kotlin? ```class Solu...
# getting-started
o
how can I translate this to Kotlin?
Copy code
class Solution(object):
  def _isValidBSTHelper(self, n, low, high):
    if not n:
      return True
    val = n.val
    if ((val > low and val < high) and
        self._isValidBSTHelper(n.left, low, n.val) and
        self._isValidBSTHelper(n.right, n.val, high)):
        return True
    return False

  def isValidBST(self, n):
    return self._isValidBSTHelper(n, float('-inf'), float('inf'))
my attempt produced this
Copy code
fun isValidChecker(
    node: Node<Int>?, low: Int, high: Int
): Boolean {
    if (node == null)
        return true

    val value = node.value

    if (value in (low + 1) until high
        && isValidChecker(node.left, low, value)
        && isValidChecker(node.right, value, high)
    )
        return true

    return false
}

fun isValidBST(node: Node<Int>?): Boolean {
    return isValidChecker(
        node, Int.MIN_VALUE, Int.MAX_VALUE
    )
}
issue is what to feed isValidBST
I want negative infinity and positive infinity with the current way that the code looks
I’m with you logically, but running the above Python variation of it makes this LeetCode question pass, running our Kotlin version fails on 7 cases
so something is off
can’t we use an operator that is exclusive?
instead of the +1 and -1 ?
dont get that part
think I broke it
Copy code
class Solution {
    fun TreeNode?.isValidBST(
        low: Double = Double.NEGATIVE_INFINITY, high: Double = Double.POSITIVE_INFINITY
    ): Boolean = this == null || 
    (`val`.toDouble() > low && `val`.toDouble() < high)
    && left.isValidBST(low, `val`.toDouble())
    && right.isValidBST(`val`.toDouble(), high)

    fun isValidBST(root: TreeNode?): Boolean {
        return root.isValidBST()
    }
}
this works on Leetcode
i insisted on having it as an extension lol