Excellent explanation, I greatly appreciate for covering all of the 3 approaches! If I am not mistaken: - Approach 1: applicable for arrays with duplicate numbers as well - Approach 2 & 3: applicable for arrays with unique number only
@@ethostypos Thank you, I also learned a 4th approach ma'am which is by using Stack! Stack = [] Largest= 0 for num in arr: Largest= num While Stack & Stack[-1] > num: Largest= max(Largest, Stack[-1]) Stack.pop() Stack.append(Largest) Return len(Stack)
Excellent explanation, I greatly appreciate for covering all of the 3 approaches!
If I am not mistaken:
- Approach 1: applicable for arrays with duplicate numbers as well
- Approach 2 & 3: applicable for arrays with unique number only
Yes. Because if duplicate elements are there, then the indices won't match with the sorted version of the array.
@@ethostypos Thank you, I also learned a 4th approach ma'am which is by using Stack!
Stack = []
Largest= 0
for num in arr:
Largest= num
While Stack & Stack[-1] > num:
Largest= max(Largest, Stack[-1])
Stack.pop()
Stack.append(Largest)
Return len(Stack)
Gyanchakshu khul gaye 😮