If the current node has only one left-subtree, then the second largest could be the right most child of that sub-tree
Else, second largest is parent
deflargest(root)ifroot.any?&&root.rightreturnlargest(root.right)endreturnroot.valueenddefsecond_largest(root)returnlargest(root.left)ifroot.any?&&(root.left&&!root.right)returnroot.valueifroot.any?&&(!root.left&&!root.right)#if both of them are false then go rightreturnsecond_largest(root.right)end
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Logic