I also did it using level order traversal, but I used two queues. The second one stores the levels.

public List<Integer> rightSideView(TreeNode root) {
List<Integer> res = new ArrayList<>();
if (root == null) return res;
Queue<TreeNode> q = new LinkedList<>();
Queue<Integer> l = new LinkedList<>();
q.add(root);
l.add(0);
int prev = -1;
while (!q.isEmpty()) {
TreeNode n = q.remove();
int lvl = l.remove();
if (lvl > prev) {
res.add(n.val);
prev = lvl;
}
lvl++;
if (n.right != null) {
q.add(n.right);
l.add(lvl);
}
if (n.left != null) {
q.add(n.left);
l.add(lvl);
}
}
return res;
}