Skip to content
We areTOP 1%

Basketball Exercise

MediumRating 1400Codeforces2-D Dynamic Programming
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

Track three states per column: the best total if the last pick is from row 1, from row 2, or if nobody is picked in this column. Each state draws only from the previous column, so the scan is O(n).

More in 2-D Dynamic Programming

2-D Dynamic Programming questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Unique Paths IILeetCodeMedium Solve Unique Paths II on LeetCode (opens in a new tab)
2Minimum Path SumLeetCodeMedium Solve Minimum Path Sum on LeetCode (opens in a new tab)
3TriangleLeetCodeMedium Solve Triangle on LeetCode (opens in a new tab)
4Basketball ExerciseCodeforcesMedium 1400Solve Basketball Exercise on Codeforces (opens in a new tab)
5Longest Common SubsequenceLeetCodeMedium Solve Longest Common Subsequence on LeetCode (opens in a new tab)
6Maximal SquareLeetCodeMedium Solve Maximal Square on LeetCode (opens in a new tab)
7Three StringsCodeforcesMedium 1500Solve Three Strings on Codeforces (opens in a new tab)
8Coin Change IILeetCodeMedium Solve Coin Change II on LeetCode (opens in a new tab)
9Longest Palindromic SubsequenceLeetCodeMedium Solve Longest Palindromic Subsequence on LeetCode (opens in a new tab)
10Edit DistanceLeetCodeMedium Solve Edit Distance on LeetCode (opens in a new tab)
11k-TreeCodeforcesMedium 1600Solve k-Tree on Codeforces (opens in a new tab)
12Hard problemCodeforcesMedium 1600Solve Hard problem on Codeforces (opens in a new tab)
13Make Them EqualCodeforcesMedium 1600Solve Make Them Equal on Codeforces (opens in a new tab)
14Zero PathCodeforcesMedium 1700Solve Zero Path on Codeforces (opens in a new tab)
15Caesar's LegionsCodeforcesMedium 1700Solve Caesar's Legions on Codeforces (opens in a new tab)
16Sleeping ScheduleCodeforcesMedium 1700Solve Sleeping Schedule on Codeforces (opens in a new tab)
17George and JobCodeforcesMedium 1700Solve George and Job on Codeforces (opens in a new tab)
18Distinct SubsequencesLeetCodeHard Solve Distinct Subsequences on LeetCode (opens in a new tab)
19Wildcard MatchingLeetCodeHard Solve Wildcard Matching on LeetCode (opens in a new tab)
20Cherry Pickup IILeetCodeHard Solve Cherry Pickup II on LeetCode (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