We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Min Max Riddle
- Discussions
Min Max Riddle
Min Max Riddle
Sort by
recency
|
110 Discussions
|
Please Login in order to post a comment
Chemistry riddles enhance problem solving skills by challenging individuals to think critically, recall specific details, and connect abstract ideas, often requiring them to recognize patterns in chemical behavior.
O(n) using the previous and next smaller element algos and dynamic programming, pass all test.
if u try to use sliding window and iterate over each length, it's O(n^2) and times out. u need to use dynamic programming concepts to achieve O(n).
the max_element inside the last for loop may make the for loop look like O(n^2), but maximalWindow has a total of n element across all maximalWindow[size], so the for loop has O(n) operations in total
in swift
Python solution with a stack. You need to split solution in 2 parts:
Go through the array and add to stack till the next number is smaller than the last value added to stack. When it happens you pop from the stack checking if value is higher than value in max windows array.
You end up with array with maximum windows for some window lengths. You have to populate the missing values with values from the right using a logic that window length for bigger window is also at least maximum for a smaller window.
`
JS code template has naming issues, HackerRank have to check the description and the code