# Reverse Odd Levels of Binary Tree (Leetcode 2415)

Problem Link: <https://leetcode.com/contest/weekly-contest-311/problems/reverse-odd-levels-of-binary-tree/>

```python
# 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 reverseOddLevels(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
        q=[root]
        c=0
        while(len(q)>0):
            
            if(c%2!=0):
                start=0
                end=len(q)-1
                while(start<=end):
                    q[start].val,q[end].val=q[end].val,q[start].val
                    start+=1
                    end-=1
            for i in range(len(q)):
                node=q.pop()
                if(node.left is not None):
                    q.insert(0,node.left)
                if(node.right is not None):
                    q.insert(0,node.right)
            c+=1
        
        return root      
```
