<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>


class Solution {
public:
    int levels(TreeNode* root){
        if(root==NULL)return 0;
        return 1+max(levels(root->left),levels(root->right));
    }
    // void nthLevel(TreeNode* root,vector<int>&v,int curr,int n){
    // if (root==NULL)return;
    // //bfs traversing
    //     if(curr==n){
    //         v[curr]=root->val; //bar bar update hoyegi
    //         return;
    //     } 
    // nthLevel(root->left,v,curr+1,n);
    // nthLevel(root->right,v,curr+1,n);
    // }   
    // vector<int> rightSideView(TreeNode* root) {
    //     int n=levels(root);
    //     vector<int>v(n,0);
    //     for(int i=0;i<n;i++){
    //         nthLevel(root,v,0,i);
    //     }
    //     return v;
    void preorder(TreeNode* root,int level,vector<int>&v){
        if(root==NULL)return;
        v[level]=root->val;
        preorder(root->left,level+1,v);
        preorder(root->right,level+1,v);
    }
    vector<int> rightSideView(TreeNode* root){
        int n=levels(root);
        vector<int>v(n,0);
        preorder(root,0,v);
        return v;
    }
};
13800