<p>Given the <code>root</code> of a binary tree, imagine yourself standing on the <strong>right side</strong> of it, return <em>the values of the nodes you can see ordered from top to bottom</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" style="width: 401px; height: 301px;" />
<pre>
<strong>Input:</strong> root = [1,2,3,null,5,null,4]
<strong>Output:</strong> [1,3,4]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> root = [1,null,3]
<strong>Output:</strong> [1,3]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the tree is in the range <code>[0, 100]</code>.</li>
	<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
        if root is None:
            return []
        
        queue = []
        res = []

        tempRoot = [root, 1]
        while tempRoot:
            if tempRoot[0].left:
                queue.append([tempRoot[0].left, tempRoot[1] + 1])
            if tempRoot[0].right:
                queue.append([tempRoot[0].right, tempRoot[1] + 1])
            
            while len(res) < tempRoot[1]:
                res.append([])

            if res[tempRoot[1] - 1]:
                res[tempRoot[1] - 1].append(tempRoot[0].val)
            else:
                res[tempRoot[1] - 1] = [tempRoot[0].val]
        
            if len(queue) > 0:
                tempRoot = queue.pop(0)
            else:
                tempRoot = None
        
        ans = []
        for level in res:
            ans.append(level[-1])
            
        return ans
16300