SDE Path

Find Minimum and Maximum in a BST

Easy

Find Minimum and Maximum in a BST

Find the minimum and maximum valued nodes in a binary search tree.

Input format

The first line contains level-order tokens representing a BST.

Output format

Print "min max" where min and max are the minimum and maximum values.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
85 79 92 38 81 N N 6 70 N 83 N 19 53 73 N N 18 29 42 66 71 N 7 N N 32 N 46 N N N N N 10
Expected output
6 92
Example 2
Input
26 11 47 1 22 37 59 N N 21 23 N 40 52 79 18 N N N N 46 48 57 N 87 N N N N N N N 58 N 91
Expected output
1 91