Dynamic Programming 101
Advanced · 4 chapters · 9 min read · Define the state, write the recurrence, and let a table remember every subproblem.
Practise this in the app All guides
What dynamic programming really is
Recursion plus memory
Dynamic programming (DP) solves a problem by breaking it into overlapping subproblems, solving each one once, and storing the result. If a plain recursive solution keeps recomputing the same calls (Fibonacci is the classic example: fib(5) calls fib(3) twice and fib(2) three times), DP turns that exponential tree into a linear or quadratic table.
Two properties tell you DP applies:
- Optimal substructure: the best answer for the whole is built from best answers to smaller parts.
- Overlapping subproblems: the same smaller parts are needed again and again.
Signals in a problem statement
- "Number of ways to" climb, decode, reach, form.
- "Minimum cost / maximum value" over a sequence of choices.
- "Longest increasing / common subsequence", "edit distance".
- "Can the string be segmented into dictionary words?"
- Grid paths moving only right or down.
- Constraints of n up to around 10³ to 10⁴ (an O(n²) table), or two strings up to about 10³ each.
The four-step recipe
- State: what does
dp[i](ordp[i][j]) mean, in one precise sentence? For example, "dp[i]is the number of ways to decode the firsticharacters". - Transition: how is
dp[i]built from smaller states? - Base cases: the smallest states whose answer you know directly.
- Order and answer: fill states so that dependencies are ready first, and say which state holds the final answer.
Most of the difficulty is step 1. Once the state sentence is right, the transition usually follows from asking "what was the last choice made?"
Core patterns with templates
1. Top-down with memoisation
from functools import lru_cache
def min_cost_climb(cost):
@lru_cache(maxsize=None)
def f(i):
if i >= len(cost):
return 0
return cost[i] + min(f(i + 1), f(i + 2))
return min(f(0), f(1))
2. Bottom-up 1D with rolling variables
def tribonacci(n):
a, b, c = 0, 1, 1
for _ in range(n):
a, b, c = b, c, a + b + c
return a
3. Counting ways over a string
def num_decodings(s):
prev2, prev = 1, int(s[0] != "0") # dp[i-2], dp[i-1]
for i in range(1, len(s)):
cur = prev if s[i] != "0" else 0
if 10 <= int(s[i - 1:i + 1]) <= 26:
cur += prev2
prev2, prev = prev, cur
return prev
Example: "226" decodes as 2-2-6, 22-6 and 2-26, so the answer is 3.
4. Segmenting with a dictionary
def word_break(s, words):
wset = set(words)
dp = [True] + [False] * len(s) # dp[i]: first i chars can be split
for i in range(1, len(s) + 1):
dp[i] = any(dp[j] and s[j:i] in wset for j in range(i))
return dp[-1]
5. Two sequences (2D table)
def lcs(a, b):
m, n = len(a), len(b)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if a[i - 1] == b[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
return dp[m][n]
Edit distance uses the same table: on a match copy the diagonal, otherwise 1 + min(insert, delete, replace), with dp[i][0] = i and dp[0][j] = j.
6. Longest increasing subsequence in O(n log n)
from bisect import bisect_left
def lis(nums):
tails = []
for x in nums:
i = bisect_left(tails, x)
if i == len(tails):
tails.append(x)
else:
tails[i] = x
return len(tails)
tails[k] is the smallest possible tail of an increasing subsequence of length k + 1.
Complexity, mistakes and edge cases
Complexity
Time is roughly number of states × work per state. Space is the number of states you keep.
| Problem | States | Time | Space (optimised) |
|---|---|---|---|
| Climbing stairs, tribonacci | n | O(n) | O(1) |
| Decode ways | n | O(n) | O(1) |
| Word break | n | O(n²) substring checks | O(n) |
| Unique paths in a grid | m × n | O(mn) | O(n) one row |
| LCS, edit distance | m × n | O(mn) | O(min(m, n)) |
| LIS (patience method) | n | O(n log n) | O(n) |
Common mistakes
- A vague state. "
dp[i]is the answer up to i" is not enough. Does it end ati, or cover the first i elements? Those are different problems. - Off-by-one between string indices and table indices. Using
dpof sizen + 1wheredp[i]refers to the firsticharacters, so characters[i - 1], avoids special cases for the empty prefix. - Wrong fill order. Each state must be computed after the states it depends on.
- Mutable default arguments or unhashable arguments with
lru_cache. Pass tuples or indices, not lists. - Recursion depth in top-down DP for n around 10⁴ or more; convert to bottom-up.
- Leading zeros in decode ways:
"0"and"06"have no valid decoding. - Space-optimising too early. Get the full table right, then roll it into one or two rows if asked.
Edge cases
Empty strings, a single element, all equal values (LIS of length 1), strings with zeros, a word list where no split works, grids with one row or one column, and identical input strings for edit distance (answer 0).
Grid paths
def unique_paths(m, n):
row = [1] * n
for _ in range(1, m):
for j in range(1, n):
row[j] += row[j - 1]
return row[-1]
Each cell is the sum of the cell above (the old row[j]) and the cell to the left (the new row[j - 1]), so one row is enough.
Variations and practise
The families you will meet
- Linear sequences: stairs, house robber, decode ways, maximum subarray. State is a position; look back one or two steps.
- Grids: unique paths, minimum path sum, maximal square. State is a cell; look up and left.
- Two strings: LCS, edit distance, distinct subsequences, interleaving. State is a pair of prefixes.
- Knapsack: subset sum, coin change, partition equal subset. State is (item, capacity). For unbounded items, iterate capacity upwards; for 0/1 items, iterate it downwards so each item is used once.
- Intervals: burst balloons, palindrome partitioning, matrix chain. State is a range
[i, j]; fill by increasing length. - Subsequence with ordering: LIS, Russian dolls, longest chain. Often sort first, then run LIS.
How interviewers twist it
They ask you to reconstruct the answer, not just its value: keep the table and walk backwards from the final state, choosing whichever transition produced the stored value. They ask for less memory: roll the table into one or two rows. They change counting to modulo 10⁹ + 7: apply the modulo at each addition.
How to explain it
Write the state sentence and the recurrence as comments first, for example # dp[i][j] = edits to turn a[:i] into b[:j]. Then the base cases. Interviewers often give most of the credit at this point, before any loop is written.
Practise
The problems below start with one-dimensional warm-ups (tribonacci, cheapest stairs), move to counting decodings and segmenting words, then grid paths, and finish with the two-sequence classics (common subsequence and edit distance) and the longest increasing subsequence. Solve each first top-down with memoisation, then convert it to a bottom-up table.
Practise
Easy
- 3187. N-th Tribonacci Number
- 3188. Min Cost Climbing Stairs
- 3196. Staircase With Custom Strides
- 3201. Domino Strip Tilings
- 3202. Staircase With Broken Steps
- 3203. Frog Over Uneven Stones
- 3204. Best Walk Along Signed Tiles
- 3205. Binary Strings Without Neighbouring Ones
- 3206. Shrink A Number To One
- 3207. Longest Warming Streak
- 3208. Fence Posts Without Three Alike
- 3209. Cheapest House Painting Plan
- 3210. Count Sorted Five Letter Words
- 3211. Two-Tone Tile Runs
- 3212. Cheapest Descent of a Number Pyramid
- 3213. Parking Lot Rows With No Adjacent Cars
- 3216. Rabbit Colony With Lifespans
- 3219. Words From a Follow Table
- 3220. Weighted Triple Pick
- 3222. Climbs Without Back-to-Back Big Steps
- 3229. Grid Walk Minimum Toll
- 3230. Grid Walk Around Roadblocks
- 3231. Lattice Routes Through A Checkpoint
- 3232. Cheapest Fall Through A Tile Wall
- 3233. Gold Run Across A Mine
- 3234. Max Path Sum In A Staircase Grid
- 3257. Pack A Bag Within The Weight Limit
- 3258. Can A Subset Hit The Target
- 3259. Reachable Sums From Dice Faces
- 3280. Can The Scoreboard Show This Total
- 3281. Longest Chain Of Booking Pairs
- 3282. Max Sum Rising Pick
- 3311. Commute By Bus Or Train
- 3312. Count Even-Sum Subtrees
- 3316. Pointer Back Home After K Steps
- 3317. Words Without Long Runs
- 3337. Secret Santa Without Self Draws
- 3338. Pebble Game With Allowed Takes
- 3339. Divisor Subtraction Game
- 3340. Halving Race Game
- 3341. Paths Through A Task Graph
- 3342. Choose K From N Table
- 3343. Longest Shared Run Of Two Logs
- 3344. Best Price For Cutting A Rod
- 3345. Grid Routes With Diagonal Steps
- 3346. Subtract A Digit Until Zero
- 3347. Sums Of Distinct Parts
- 3348. Short Words With Limited Letters
- 3349. Exactly K Heads From Biased Coins
- 3350. Mirror Check Queries
- 3351. Ordered Splits Into K Parts
- 3352. Gentle Sequences
- 3353. Minimum Starting Energy For A Hike
- 3354. Seating K Guests With Gaps
- 3355. Picking Without Three In A Row
- 3356. Darts To An Exact Score
- 3357. Digit Strings With A Given Sum
- 3358. Words With Exactly K Echoes
- 3359. Rising Column Picks
- 3360. Flag Pole Stripes
- 3361. Knight Marching East
- 3362. Parity Hopping Pick
- 3363. Ladder Board Dice Sequences
- 3364. Alternating Trio Of Buildings
- 3365. Best Alternating Stretch
- 3440. Pair Up Neighbouring Dancers
- 3441. Consecutive Bonus Picks
- 3442. Solo Or Paired Guests
- 3443. Tower Moves Between Neighbouring Pegs
- 3444. Word Chain Pick
- 3445. Codes With An Even Count Of Zeros
- 3451. Prune For The Heaviest Tree
- 3452. Two Visits At Least K Days Apart
- 3453. Stairs With A Rented Jetpack
- 3454. Longest Snake Of Neighbouring Values
- 3455. Back To The Start After N Coin Steps
- 3456. Never Skip Two Houses In A Row
- 3457. Light Every Tile Of A Corridor
- 3458. Social Distancing In A Two-Row Cinema
- 3459. Currency Swaps Over A Week
- 3460. Count Ways To Grow A Number
- 3466. Two Machines With Setup Costs
- 3475. Pogo Stick Staircase
- 3510. Bowling Pins In Pairs
- 3520. Fewest-Sum Plus Signs
- 3526. Pairs And Trios
- 3529. Landing Exactly On N
- 3532. Lucky Ticket Count
- 3585. Ball Back To The Captain
Medium
- 3189. Unique Paths
- 3190. Longest Increasing Subsequence
- 3191. Longest Common Subsequence
- 3192. Word Break
- 3193. Decode Ways
- 3197. Frog With Long Leaps
- 3198. Cheapest Transit Passes
- 3199. Trail With Rising Labels
- 3200. Climbs With A Limited Number Of Big Leaps
- 3214. Best Segment With One Removal
- 3215. Best Segment With One Squared Value
- 3217. Three-Row Wall of Dominoes
- 3218. Dominoes and Corner Tiles Strip
- 3221. Most Characters From N Presses
- 3223. Attendance Records Without Trouble
- 3224. Fewest Stops Of A Refuelling Truck
- 3225. Holiday Itinerary Around Rest Days
- 3226. Robbing A Ring Of Cottages
- 3227. Pick Values With No Two Within Distance
- 3228. Choose Non-Touching Seats For Max Comfort
- 3235. Largest Square Of Lit Tiles
- 3236. Largest Bordered Square
- 3237. Paths That Pick Up Exactly K Keys
- 3238. Paths With Sum Divisible By K
- 3239. Falling Path Avoiding The Same Column
- 3240. Fewest Starting Hit Points In A Vault
- 3241. Product Path With Largest Value
- 3242. Ball Leaving The Board In K Moves
- 3243. Count Rising Trails In A Grid
- 3244. Maximal Rectangle Of Lit Tiles
- 3245. Two Robots Collecting Berries
- 3246. Paths Of Exact Length On A Keypad Grid
- 3247. Smallest Path Score With Obstacles And Bonus
- 3248. Water Flow Steps To Every Cell
- 3252. Largest Square Of Equal Letters
- 3253. Max Area Rectangle With Swappable Columns
- 3260. Split Weights Into Two Equal Piles
- 3261. Signs That Reach The Target
- 3262. Smallest Leftover After Smashing Rocks
- 3263. Pack Strings Under Two Budgets
- 3264. Ways To Pay A Bill
- 3265. Fewest Coins With Limited Supply
- 3266. Largest Value Under Exact Weight
- 3267. Cheapest Ingredients For A Recipe Weight
- 3268. Bounded Shelf Of Copies
- 3269. Group Knapsack Of Menus
- 3270. Equal Sum With Fewest Moves Between Piles
- 3271. Count Subsets Under A Weight Limit
- 3272. Distinct Subset Sums
- 3273. Two Bags With Weight Limits
- 3274. Subset Sum Divisible By M
- 3283. Longest Chain Of Divisible Numbers
- 3284. Longest Mountain Pick
- 3285. Longest Common Pick Of Three Words
- 3286. Cheapest Deletions To Match Two Words
- 3287. Weave Two Messages
- 3288. Best Dot Product Of Two Picks
- 3289. Longest Mirror Pick
- 3290. Count Ways To Split Into Mirrors
- 3291. Cheapest Polygon Triangulation
- 3292. Guessing Game With Penalties
- 3293. Ways To Bracket A Boolean Expression
- 3294. All Results Of Bracketing
- 3295. Best Score From Two Ended Multipliers
- 3313. Trading With A Cool-Off Day
- 3314. Lane Changes For A Delivery Robot
- 3315. Best Alternating Sum Of A Pick
- 3318. Split Into K Equal Groups
- 3319. Square From Matchsticks
- 3320. Fewest Work Sessions
- 3321. Assign Scooters To Riders
- 3322. Fairest Cookie Handout
- 3323. Looting A Tree Of Houses
- 3324. Longest Zigzag Walk Down A Tree
- 3325. Fewest Guards For Every Road
- 3326. Numbers Up To N With Given Digit Sum
- 3327. Count Numbers With Non-Decreasing Digits
- 3366. Two-Column Tower Builds
- 3367. Knapsack With Huge Weights
- 3368. Best Stretch Of At Least K
- 3369. Quiz Points With Skips
- 3370. Exactly K Non-Adjacent Picks
- 3371. Smooth A Terrain
- 3372. Warehouse Stock Plan
- 3373. Machine Replacement Plan
- 3374. Closest Row Pick Sum To Target
- 3375. Rewards Taken Only When Larger
- 3376. Highest Scoring Team Without Conflicts
- 3377. Splice A Stretch Between Two Arrays
- 3378. Best Coins From Pile Tops
- 3379. Paint A Street With Many Colours
- 3380. Cut A Sheet Into Squares
- 3381. Walks Of Exactly K Roads
- 3382. Course Durations Critical Path
- 3383. Expected Rolls To Reach A Total
- 3384. Growing Take Limit Game
- 3385. Take Up To Three From The Front
- 3386. First Player Margin
- 3387. Split Into K Parts Minimising Sum Of Maxima
- 3388. Neat Paragraph Layout
- 3389. Bookshelf Rows Of Least Height
- 3390. Best Sum After Grouping Into Blocks
- 3391. Courier Event Orders
- 3392. Bounded Candy Distribution
- 3393. Ordered Lists Where Each Divides The Next
- 3394. Splitting A Group Into Teams
- 3395. Colouring A Roundabout
- 3396. Fountain Of Cups
- 3397. Keypad Press Messages
- 3398. Longest Positive Product Stretch
- 3399. Longest Gentle Letter Pick
- 3400. Rumour Spread With Delay And Forgetting
- 3401. Orchard Rows With Walking Penalty
- 3402. Count Three-Phase Picks
- 3403. Non-Overlapping Segments On A Line
- 3404. Fewest Wasted Seats With Limited Resizes
- 3405. Two Mirror Picks With Largest Product
- 3406. Factory Floors With Transfer Fees
- 3407. Most Hops Under A Height Rule
- 3408. Sum Of Distinct-Letter Counts Over Substrings
- 3409. Best Profit Trading Down A Grid
- 3410. K-th Route In Dictionary Order
- 3411. Carve A Wooden Board For Profit
- 3412. Splice Two Rows Into A Long Ascent
- 3413. Longest Pick With Shrinking Gaps
- 3414. Clearing Contaminated Train Cars
- 3415. Max Balanced Pick Sum
- 3416. White Tiles Left Under Carpets
- 3418. Sturdy Brick Walls
- 3419. Great Two-Group Partitions
- 3423. Numbers Without Equal Neighbouring Digits
- 3424. K-th Calm Bit String
- 3425. Hiking Profiles Under A Ceiling
- 3426. Cheapest Coin Path With Route
- 3427. Longest Pick With Matching Pair Remainders
- 3446. Fewest Skips To Arrive On Time
- 3447. Best Team With Two Roles
- 3448. Splits With Light Pieces
- 3449. Meal Plans With A Treat Limit
- 3450. Best-Of Series Odds
- 3461. Rest Stops On A Road Trip
- 3462. Permutations With K Descents
- 3463. Routes With At Most K Turns
- 3464. Largest Unbroken Postage Range
- 3465. Expected Turns On A Ladder Board
- 3467. Pair Up Neighbours In A Tree
- 3468. Longest Even-Weight Trail In A Tree
- 3469. Break Every Hidden Copy
- 3470. Widest Spread Partition
- 3471. Even Loads For K Trucks
- 3472. Unordered Splits Into K Parts
- 3473. Ordered Sums Without Repeated Neighbours
- 3474. Escalating Takeaway
- 3476. Know When To Stop Rolling
- 3477. Pieces With A Duplicate Charge
- 3478. Sparse Numbers Up To N
- 3479. Lights Out On A Line
- 3480. Total Ink For Page Numbers
- 3481. Treasure Hunt In Numbered Order
- 3482. Snaking East Through A Field
- 3483. Longest Domino Line
- 3484. Bakery With Spoilage
- 3485. Neighbours Sharing A Factor
- 3486. Gallery Visit Before Closing
- 3487. Workout Weeks With Recovery Days
- 3488. Fishing Lakes Along A Trail
- 3489. Fix One Reading For The Longest Rise
- 3490. Staffing Plan With Hiring And Layoff Costs
- 3491. Sums of K Squares
- 3492. Touring Band Schedule
- 3493. Horse Race Matchups
- 3494. Night Shift Rosters
- 3495. Bit Strings With Exactly K Runs
- 3496. Shipping In Full Crates
- 3498. Finish The Bracket Template
- 3500. Doubling Ladders
- 3502. Loading Cars Onto A Two-Lane Ferry
- 3503. Hike With Snack Stops
- 3504. Phone Tree Broadcast
- 3505. Spending Limited Coupons
- 3506. Lockers For Parcels
- 3507. Buy Low, Store, Sell High
- 3508. Cover Points With Priced Planks
- 3509. Finishing On A Double
- 3511. Smallest Word Along A Grid Route
- 3512. Spelling A Word On A Letter Board
- 3513. Waiting For A Streak Of Heads
- 3514. Best Stretch With Sign Flips
- 3515. Overlapping Relay Chain
- 3516. Strongest XOR Of K Picks
- 3517. Hike With Rest Days
- 3518. Suit Combo Cards
- 3519. Exactly K Stops On A One-Way Trail
- 3521. Fruit Stand With Free Follow-Ups
- 3522. Quiz With Lifelines
- 3523. Picks Divisible By Three In A Digit String
- 3524. Best Rising Pick Of Exact Length
- 3525. Routes With An Exact Travel Time
- 3527. Words With K Backward Pairs
- 3528. Mirror Pieces Worth Their Square
- 3530. Crossing On Wobbly Stones
- 3531. Train Built From Both Ends
- 3533. Rook Rides To The Corner
- 3534. Paint A Picket Fence
- 3535. Words With Every Letter Paired
- 3536. Distinct-Value Picks Of Size K
- 3537. Boost Pads Along A Track
- 3538. Rising Picks With Sum Divisible By K
- 3539. One-Row Minesweeper Fillings
- 3540. Bundle Deals Shopping List
- 3541. Calm Words Up To A Bound
- 3542. Picks With A Gap Penalty
- 3546. Longest Near-Common Pick
- 3574. Rising Choices From Ranges
- 3575. Rising Pick Around A Ring
- 3579. Knockout Bracket Odds
- 3584. Short Hike Of Exactly K Cells
- 3586. Never The Same Flavour Twice In A Row
Hard
- 3194. Edit Distance
- 3195. Regular Expression Matching
- 3249. Max Score Path With Path Counting
- 3250. Round Trip Cherry Harvest
- 3251. Cheapest Grid Path With Limited Teleports
- 3254. Three-Colour Tile Mural
- 3255. Domino Placement On A Grid With Holes
- 3256. Fewest Moves To Collect Keys In Order
- 3275. Profitable Project Crews
- 3276. Fewest Coins Paid With Change
- 3277. Ways To Build Exact Change From Limited Coins
- 3278. Max Value With A Minimum Item Count
- 3279. Knapsack With Item Dependencies
- 3296. Cheapest Order To Multiply Matrices
- 3297. Cheapest Way To Saw A Plank
- 3298. Fewest Printer Strokes
- 3299. Clearing Coloured Blocks For Points
- 3300. Erase A Row By Mirror Chunks
- 3301. Fewest Cuts Into Mirror Pieces
- 3302. Longest Mirror From Two Words
- 3303. Count Hidden Copies Of A Word
- 3304. Wildcard Pattern Matcher
- 3305. Scrambled Word Check
- 3306. Smallest Common Supersequence
- 3307. Shortest String Hidden In Neither Word
- 3308. Fewest Edits To Make Every Kth Rising
- 3309. Count Rising Picks Of Length K
- 3310. Longest Common Rising Pick
- 3328. Two Rounds Of Trading
- 3329. At Most K Rounds Of Trading
- 3330. Trading With Short Sales
- 3331. Words That Avoid A Banned Pattern
- 3332. Guests Wearing Distinct Hats
- 3333. Seating Exam Takers Without Peeking
- 3334. Cut A Tree So Each Part Has One Marker
- 3335. Integers With Digit Sum In A Window
- 3336. Balanced Divisible Integers
- 3417. Sticks Visible From The Left
- 3420. Routes Across A Huge Board With Few Pits
- 3421. Stacking Crates By Strength
- 3422. Best Grouping Of Partners
- 3428. Permutations Matching A Rise And Fall Pattern
- 3429. Playlists With A Repeat Gap
- 3430. Dice Rolls With Run Limits
- 3431. Arrays With Exactly K Leader Changes
- 3432. Job Plan Over D Days
- 3433. Split Digits Into A Rising Number List
- 3434. Two Painters For The Walls
- 3435. Split Row Game Keeping The Smaller Half
- 3436. Build A Word From Dictionary Columns
- 3437. Paint Houses Into Exact Neighbourhoods
- 3438. Two-Finger Typing
- 3439. Spell With A Rotating Ring
- 3497. Shrink a Row by Merging Twins
- 3499. Rearranged Digits Divisible By Eleven
- 3501. Paint Black Cells With Square Strokes
- 3543. Cheapest Insertions And Deletions To A Mirror
- 3544. Shortest Repeat-Compressed Form
- 3545. Clearing A Row Of Coloured Beads
- 3547. Out-And-Back Survey Route
- 3548. Longest Balanced Pick With Three Bracket Types
- 3549. Collecting Every Sticker Type
- 3550. Carve Out A Group Of Size K
- 3551. Pairs Exactly K Apart In A Tree
- 3552. Fuel-Limited Road Trip
- 3553. Words Hiding A Secret
- 3554. Picks Whose GCD Is One
- 3555. Mountain Ranges With K Peaks
- 3556. Toppling Pins In A Row
- 3557. Emptying Plates At Random
- 3558. Wire Two Groups of Ports
- 3559. Fill Customer Orders with Identical Items
- 3560. Routes Touching Every Town Once
- 3561. Fewest Frequencies for Radio Towers
- 3562. Numbers with Small Digit Products
- 3563. K-th Number with a Given Digit Sum
- 3564. Lucky Sevens in a Range
- 3565. Merging Piles Around a Table
- 3566. Non-Crossing Same-Colour Pairings
- 3567. Longest Shared Mirror Pick
- 3568. Shared Pick Count
- 3569. Rooks On A Board With Holes
- 3570. Serving Customers Along A Street
- 3571. Aligning Gene Strings With Gap Costs
- 3572. Folding A Strand For Most Pairs
- 3573. Typing With A Copy Shortcut
- 3576. Settling Debts With Fewest Transfers
- 3577. Frog Leaps With Squared Cost
- 3578. Gondola Groups Of Strangers
- 3580. Two Gym Routes That Meet Once
- 3581. Bead Strings With No Twin Neighbours
- 3582. Shared Order Across Many Rankings
- 3583. Best Score For A Bracket Template