Given a list of integers, return true if the list is sorted in non-decreasing (ascending) order, and false otherwise. A non-decreasing list allows equal adjacent elements. An empty list or a list with a single element is considered sorted. Return true for a null input.

Examples:

Input: nums = [1, 2, 3, 4, 5] Output: true Explanation: Each element is greater than or equal to the previous element Input: nums = [1, 2, 2, 4, 5] Output: true Explanation: Equal adjacent elements are allowed in non-decreasing order Input: nums = [5, 3, 1] Output: false Explanation: 3 is less than 5, so the list is not in ascending order Input: nums = [] Output: true Explanation: An empty list is considered sorted Input: nums = [42] Output: true Explanation: A single-element list is always sorted
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay July 2026

Contest runs July 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In