Sum of Increasing Product Blocks

You are given an integer n.

Define a sequence of blocks such that:

  • The 1st block contains the number 1.
  • The 2nd block contains the product of the next 2 consecutive integers.

In general, the ith block contains the product of the next i consecutive integers, continuing from where the previous block ended.

Let F(n) denote the sum of the first n blocks.

Return F(n) modulo (109 + 7).

Example 1:

Input: n = 2

Output: 7

Explanation:

  • Block 1: 1
  • Block 2: 2 × 3 = 6

F(2) = 1 + 6 = 7

Example 2:

Input: n = 4

Output: 5167

Explanation:

  • Block 1: 1
  • Block 2: 2 × 3 = 6
  • Block 3: 4 × 5 × 6 = 120
  • Block 4: 7 × 8 × 9 × 10 = 5040

F(4) = 1 + 6 + 120 + 5040 = 5167

Now Your Turn!

Pick the correct output for the given input

Input: n = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 ≤ n ≤ 1000
  • Each block contains exactly i consecutive unused integers.
  • The result must be returned modulo 109 + 7.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int sumOfBlocks(int n) {
// Your code goes here
}
};
Test Case

Input:

N