Check Array is sorted or not

PHOTO EMBED

Sat May 25 2024 21:26:06 GMT+0000 (Coordinated Universal Time)

Saved by @ayushg103 #c++

bool check(vector<int>& nums) {
        int count = 0 ;
        if (nums[0] < nums[nums.size()-1]) count++ ;
        for (int i=1; i<nums.size(); i++){
            if (nums[i] < nums[i-1]){
                count++ ;
                if (count > 1) return false ;
            }
        }
        return true ;
    }
content_copyCOPY