Welcome to LeetCode Discuss.
This is a place to ask questions related to only OJ problems.
Please read the FAQ to help yourself making the best use of Discuss.
Is the input array assumed to always be sorted ?
No. There is a test case which is unsorted. I implemented a quick sort.
Does anyone have a better solution without sorting the input?
the result is in non-descending order, so we cant go over sorting part. so sorting input is the most efficient way.