#3351
Sum of Good Subsequences
international master · 1965 · lc hard +32 · 30.8% accepted · 157 likes · top 8%
Description
You are given an integer array nums. A subsequence is called good if the absolute difference between every pair of adjacent elements in the subsequence is exactly 1.
Return the sum of all elements across every possible good subsequence of nums.
Since the answer may be very large, return it modulo 109 + 7.
A subsequence of size 1 is always considered good.
Code
1
2
3