text: /*
      class TreeNode {
          constructor(label) {
              this.label = label;
              this.left_ptr = null;
              this.right_ptr = null;
          }
      }
  
      Complete the function below.
      The function accepts a TREENODE as input
      and is expected to return an INTEGER ARRAY.
  */
  
  // time complexity: O(n)
  // space complexity: O(n)
  // BFS approach using a queue
  function right_view(root) {
    if (!root) return [];
  
    let queue = [[0, root]],
      levelObj = {},
      result = [];
  
    while (queue.length > 0) {
      let [level, current] = queue.shift();
      if (!levelObj[level]) levelObj[level] = [];
      levelObj[level].push(current.label);
  
      if (current.left_ptr) queue.push([level + 1, current.left_ptr]);
      if (current.right_ptr) queue.push([level + 1, current.right_ptr]);
    }
  
    for (let key in levelObj) {
      // push each level last value
      result.push(levelObj[key][levelObj[key].length - 1]);
    }
    return result;
  }
  
  // passed all tests in IK IDE
  