Check if Array is Sorted Solution

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
275 B
3
Indexable
Never
int isSorted(int n, vector<int> a) {
    // Write your code here.
    int sortedStatus = 1;
    for(int i = 0; i< n - 1; i++){
        if(a[i]> a[i + 1]){
            sortedStatus = 0 ;
            return sortedStatus;
        }
    }

    return sortedStatus;
}
Leave a Comment