class MagicIndex {
public:
    bool findMagicIndex(vector<int> A, int n) {
        // write code here
        int start = 0;
        int end = n-1;
        while(start <end ){
            int center = (start +end)/2;
            if(A[center] == center) return true;
            if(A[center] > center) {
                end = center;
            }else{
                start = center;
            }
        }
        return A[start] == start;
    }
};