Ezvor

3299. Sum of Consecutive Subsequences

HardArray Preparing judge… LeetCode
ArrayHash TableDynamic Programming

Hints

Hint 1
Try to count the number of times each element occurred in a consecutive subsequence, then you can find the answer easily.
Hint 2
Think of dynamic programming as a solution to calculate the number in the previous hint.
Hint 3
Let left_inc[i] be the number of increasing consecutive subsequences ending at nums[i] (except for nums[i] itself).
Hint 4
Let right_inc[i] be the number of increasing consecutive subsequences starting at nums[i] (except for nums[i] itself).
Hint 5
Then nums[i] is in left_inc[i] + right_inc[i] + left_inc[i] * right_inc[i] + 1 increasing subsequences.
Hint 6
Do the same for decreasing consecutive subsequences.