05. Max Score from Subarray Mins
β GFG solution to the Max Score from Subarray Mins problem: find maximum sum of smallest and second smallest elements across all subarrays using optimized approach. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [4, 3, 5, 1]
Output: 8
Explanation: All subarrays with at least 2 elements and find the two smallest numbers in each:
[4, 3] β 3 + 4 = 7
[4, 3, 5] β 3 + 4 = 7
[4, 3, 5, 1] β 1 + 3 = 4
[3, 5] β 3 + 5 = 8
[3, 5, 1] β 1 + 3 = 4
[5, 1] β 1 + 5 = 6
Maximum Score is 8.Example 2
π Constraints
β
My Approach
Basic Single Pass
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated