Submitting Q1 - #463
Conversation
|
Your solution is correct and efficient, running in O(n) time and using O(1) space. However, there are a few points to improve:
|
|
Your solution is correct and efficient, with O(n) time and O(1) space complexity. This is a good approach, but it is more complex than necessary. The standard solution for this problem is to simply add the difference whenever the current price is higher than the previous day's price. For example: This approach is simpler and achieves the same result. Your method of tracking local minima and maxima is valid, but it requires more code and has edge cases to handle (like the final segment). The standard solution is more straightforward. Strengths:
Areas for improvement:
Overall, your solution is correct, but I recommend adopting the simpler standard solution for clarity. |
No description provided.