Scala solution with recursion
Perform an in order traversal of the tree the kth item we encounter is the value to return.\n```\n  object Solution {\n    def kthSmallest(root: TreeNode, k: In
Perform an in order traversal of the tree the kth item we encounter is the value to return.\n```\n  object Solution {\n    def kthSmallest(root: TreeNode, k: Int): Int = {\n      def inOrderTraversal(root: TreeNode, count: Int): (Int, Option[Int]) = {\n        if (root == null) (count, None)\n        else {\n          inOrderTraversal(root.left, count) match {\n            case (_, Some(solution: Int)) =>\n              (0, Some(solution))\n            case (countRemaining: Int, None) if countRemaining == 1 =>\n              (0, Some(root.value))\n            case (countRemaining: Int, None) =>\n              inOrderTraversal(root.right, countRemaining - 1)\n          }\n        }\n      }\n\n      inOrderTraversal(root, k)._2.get\n    }\n  }\n````
['Recursion', 'Scala']