ProgrammingModerateProduct-company MCQ pattern

What is the time complexity of s[::-1] for a string of length n in CPython?

  1. A. O(1), because slices of strings are views
  2. B. O(log n), because it uses binary search
  3. C. O(n), because it builds a new reversed copy
  4. D. O(n squared), because each character is moved repeatedly

Correct answer: C. O(n), because it builds a new reversed copy

Strings are immutable and have no slice views, so the reversed result is a new string built in one pass. That costs O(n) time and O(n) extra memory.

More Python Programming questions

Exams that ask this topic