easiest and fastest c++ solution
Intuition\nbreadth first search from given position of one\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nbinary search to find ne
# Intuition\nbreadth first search from given position of one\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nbinary search to find next valid index\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:o(nlong(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: o(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& b, int k) {\n        vector<int> d(n,-1);\n        set<int> s;\n        for(int i:b)s.insert(i);\n        queue<int> q;\n        map<int,bool> vis; \n        vis[p]=true;\n        q.push(p);\n        int dis=0;\n        vector<set<int>> vs(2);\n        for(int i=0;i<n;i++){ vs[i%2].insert(i); }\n        for(int j:b)vs[j%2].erase(j);\n        vs[p%2].erase(p);\n        while(q.size()){\n            int sz=q.size();\n            while(sz--){\n                int a=q.front();\n                q.pop();\n                d[a]=dis;\n                int z=a;\n                int mn=max(0,a-k+1);\n                int y=a-mn;\n                int j=mn+(k-1-y);\n                int p=j;\n            \n                vector<int> v;\n                int mx=mn+k-1;\n                for(auto k1=vs[j%2].lower_bound(j) ;k1!=vs[j%2].end()&&*k1<=(a+k-1)&&(mx+((*k1-p)/2)<n);k1++){\n                 \n                if(vis[*k1]==false){\n                    vis[*k1]=true;\n                    q.push(*k1);\n                    v.push_back(*k1);\n                }\n                    \n                    \n                }\n                for(int i:v)vs[i%2].erase(i);\n              \n            }\n            dis++;\n            \n        }\n        return d;\n    }\n};\n```
['Binary Search', 'Breadth-First Search', 'C++']