Easy C++ Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n  int SortCount(vector<int>ans){\n  int count=0;\n  vector<int>take=ans;\n  sort(take.begin(),take.end());\n  unordered_map<int,int>mapping;\n  for(int i=0;i<take.size();i++){\n    mapping[take[i]]=i;\n  }\n  for(int i=0;i<ans.size();i++){\n     while(i!=mapping[ans[i]]){\n      swap(ans[i],ans[mapping[ans[i]]]);\n      count++;\n     }\n  }\n  return count;\n}\nvoid helper(TreeNode* root,vector<int>&ans,int &count){\n  if(root==NULL)return;\n  queue<TreeNode*>Q;\n  Q.push(root);\n  Q.push(NULL);\n  while(!Q.empty()){\n    TreeNode* newnode=Q.front();\n    Q.pop();\n    if(newnode==NULL){\n      for(auto it:ans)cout<<it<<" ";\n      cout<<endl;\n      count=count+SortCount(ans);\n      ans.clear();\n      if(!Q.empty()){\n        Q.push(NULL);\n      }\n    }\n    else{\n      ans.push_back(newnode->val);\n      if(newnode->left){\n        Q.push(newnode->left);\n      }\n      if(newnode->right){\n        Q.push(newnode->right);\n      }\n    }\n  }\n}\nint minimumOperations(TreeNode* root) {\n  if(root==NULL){return 0;}\n  vector<int>ans;\n  int count=0;\n  helper(root,ans,count);\n  return count;\n}\n};\n```
['C++']