1
var rightSideView = function (root) {6
while (queue.length > 0) {7
let queueLength = queue.length;9
// As we are giving priority to right node,10
// first node will always be the one that we want in output11
ans.push(queue[0].val);13
for (let i = 0; i < queueLength; i++) {14
// Ignore TC of queue.shift (assuming we have queue implementation with O(1) TC)15
let current = queue.shift();17
// Always give priority to right node18
if (current.right) queue.push(current.right);19
if (current.left) queue.push(current.left);