Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Isabela Vlls
EASY solution sorting and using two pointers /O(nlogn)

Isabela Vlls

Nov 26, 2024

class Solution: def sort(self, arr): sortedVersion = sorted(arr) left, right = 0, len(arr)-1 while left < len(arr) and arr[left] == sortedVersion[left]: left += 1 while right >= 0 and arr[right] == sortedVersion[right]: right -= 1 if left >= right: # if it's already sorted return 0 count = right - left + 1 return count

0

0

Comments
Comments

On this page