Rightmost value on each level
Write rightmost_per_level(root): given the root of a binary tree, return the value of the last node of every level, reading each level from left to right, from the root's level down. It is what you would see looking at the tree from its right side. An empty tree gives []. Each TreeNode has val, left and right.
The tests call the provided run_rightmost_per_level(values), where values lists the tree level by level with null for a missing child: [1, null, 2, 3] is a root 1 with only a right child 2, whose left child is 3.
Examples
run_rightmost_per_level([5,3,8,1,null,null,9])→[5,8,9]run_rightmost_per_level([1,2,3,4])→[1,3,4]run_rightmost_per_level([])→[]