Skip to content
We areTOP 1%

Count the Arrays

MediumRating 1700CodeforcesCombinatorics & Modular Arithmetic
Solve on Codeforces(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

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).

More in Combinatorics & Modular Arithmetic

Combinatorics & Modular Arithmetic questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Two ArraysCodeforcesMedium 1600Solve Two Arrays on Codeforces (opens in a new tab)
2Count All Valid Pickup and Delivery OptionsLeetCodeHard Solve Count All Valid Pickup and Delivery Options on LeetCode (opens in a new tab)
3Count the ArraysCodeforcesMedium 1700Solve Count the Arrays on Codeforces (opens in a new tab)
4Count AnagramsLeetCodeHard Solve Count Anagrams on LeetCode (opens in a new tab)
5AquaMoon and ChessCodeforcesHard 1900Solve AquaMoon and Chess on Codeforces (opens in a new tab)
6Divide and SumCodeforcesHard 1900Solve Divide and Sum on Codeforces (opens in a new tab)
7Number of Ways to Reorder Array to Get Same BSTLeetCodeHard Solve Number of Ways to Reorder Array to Get Same BST on LeetCode (opens in a new tab)
8Modular StabilityCodeforcesHard 2000Solve Modular Stability on Codeforces (opens in a new tab)
9Coprime SubsequencesCodeforcesHard 2000Solve Coprime Subsequences on Codeforces (opens in a new tab)
10Count the Number of Ideal ArraysLeetCodeHard Solve Count the Number of Ideal Arrays on LeetCode (opens in a new tab)
11Gerald and Giant ChessCodeforcesHard 2200Solve Gerald and Giant Chess on Codeforces (opens in a new tab)
12Devu and FlowersCodeforcesHard 2300Solve Devu and Flowers on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account