print along the way, no 2 stacks, no reversing list
\n    fun postorder(root: Node?): List<Int> {\n        if (root == null) return emptyList()\n\n        class CustomNode(val node: Node, var count: Int) // count
```\n    fun postorder(root: Node?): List<Int> {\n        if (root == null) return emptyList()\n\n        class CustomNode(val node: Node, var count: Int) // count tracks the child being process\n        val list = mutableListOf<Int>()\n\n        val stack = Stack<CustomNode>()\n        stack.add(CustomNode(root, -1))\n\n        while (!stack.isEmpty()) {\n            val cn = stack.pop()\n            if(cn.node.children.isNullOrEmpty()) {\n                list.add(cn.node.`val`)\n                continue\n            }\n            if (cn.count == cn.node.children?.lastIndex) { // all children processed\n                list.add(cn.node.`val`)\n            } else {\n                cn.count++ // point to next child, process its subtree\n                stack.push(cn) // push back parent again\n                val child = CustomNode(cn.node.children!![cn.count]!!, -1)\n                stack.push(child)\n            }\n        }\n\n        return list\n    }\n```
['Kotlin']