Check if a List is Sorted in Python

🚀 Day 24 – Check if a List is Sorted (Python) 💻 Today’s task: Implement a function to check whether a list is sorted or not. 🔍 The goal is to verify if elements are in ascending (or descending) order. 📌 This exercise helped me understand: • List traversal 🔁 • Comparison logic ⚙️ • Writing clean and efficient functions ✨ ✨ A simple yet important problem for building strong programming fundamentals. 📈 Staying consistent and improving step by step. #Python #100DaysOfCode #CodingJourney #Programming #ProblemSolving #Developer #LearnToCode #Tech #PythonTips #DataStructures

  • text

My suggestion is compare the element at index 0 with index 1, then proceed with subsequent elements. If all comparisons satisfy the condition, return that the array is sorted. This approach takes O(n) but ur code take O(nlogn) time complexity Space complexity O(1)

To view or add a comment, sign in

Explore content categories