Build Array Where You Can Find The Maximum Exactly K Comparisons

You are given three integers n, m, and k. Consider the following algorithm to find the maximum element of an array of positive integers: scan the array from left to right, and each time an element is strictly greater than every element seen so far, update the current maximum and increase search_cost by 1.

Build an array arr with the following properties:

  • arr has exactly n integers.
  • 1 <= arr[i] <= m where 0 <= i < n.
  • After applying the mentioned algorithm to arr, the value search_cost is equal to k.

Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 10^9 + 7.

Example 1
Inputn = 2, m = 3, k = 1
Output6
The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2], and [3, 3].
Example 2
Inputn = 5, m = 2, k = 3
Output0
There are no possible arrays that satisfy the mentioned conditions.

Constraints

  • 1 <= n <= 50
  • 1 <= m <= 100
  • 0 <= k <= n

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate