for space comp just create one iteration index like => iterator = len(num) -1 and every greater value puts original array which is num and iterator-- this is O(1) space!
It's not accurate to say that the biggest values are on the outside. The second biggest value could be the second or second-to-last element. It would be accurate to say that the biggest value will always be on the outside.
Master Data Structures & Algorithms For FREE at AlgoMap.io!
Spitting straight value. Thanks for these
It's what I do
for space comp just create one iteration index like => iterator = len(num) -1 and every greater value puts original array which is num and iterator-- this is O(1) space!
Great explanation, thanks a lot for sharing
Thanks, your content is brilliant. I hope you'll touch monotonic stack, double heap, prefix sum...
Thanks! Will there be more easy and medium problems where we can I apply the two pointer (indices) technique?
Many thanks for a great explanation!
You're very welcome 🥰
Perfectooo amigo
It's not accurate to say that the biggest values are on the outside. The second biggest value could be the second or second-to-last element.
It would be accurate to say that the biggest value will always be on the outside.
Sorry if this is stupid but why not use the insert method instead of append rather than reverse the array at the end?
That will be inefficient because inserting at beginning is slow
hmm, but what if they weren't in non decreasing order
Sort