Check if Array is Sorted
Fundamentals & Basic Operations DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Check if an array is sorted in ascending/non-decreasing order, Arrays, Time Complexity, Space Complexity, Big O Notation, Loops, Conditional Statements, Sorting, brute force, comparison operations, traversal optimization, array traversal, time complexity analysis, If-Else Statement, Brute-Force Search, Single-Pass Algorithms.
Check if Array Is Sorted Problem Statement Given an array of integers of size N, write a program to check if the given array is sorted in non decreasing (ascending / increasing) order. If the array is sorted, return True, otherwise return False. Note: Two consecutive equal values are considered to be sorted. Input Specification The first line contains an integer N, representing the size of the array. The second line contains N integers, representing the elements of the array. Output Specification Return True if the array is sorted in non decreasing order, False otherwise. Sample Test Cases Example 1: Input: Output: True Explanation: The given array is sorted, i.e., every element in the array is smaller than or equal to its next value. Example 2: Input: Output: False Explanation: The given array is not sorted. Element 5 is not smaller than or equal to 4 (its next value).