Count the Arrays
MediumRating 1700CodeforcesCombinatorics & Modular Arithmetic
Approach hintTry it first, then revealHide
Choose the n - 1 distinct values, pick which non-maximum value repeats, and send every other non-maximum value to the left or right of the peak. Multiply C(m, n - 1), n - 2 and 2^(n - 3).