3203. Find Minimum Diameter After Merging Two Trees | Weekly Leetcode 404

  Рет қаралды 563

codingMohan

codingMohan

Күн бұрын

Пікірлер: 3
@beeramrahulreddy11
@beeramrahulreddy11 2 ай бұрын
Hey, can you also touch upon today's 3rd problem of weekly contest?
@tommyshelby6277
@tommyshelby6277 2 ай бұрын
I will try to explain, inviting @codingmohan for review and optimizations possible FIRST:: Consider it as an LIS problem where your goal is to find the longest increasing subsequence so pseudo code becomes like: for i in range(n): for j in range(i): dp[i]=max(dp[i], dp[j]+1) # easy SECOND:: Now the contraint added is your j'th element should be having a property, that element at index j, and element at index i, their sum and then remainder must be having same value , say `rem`, where the previous subsequence ended at index j, with sum and then remainder, `rem` If you see closely, we just added another dimension `rem` whose value ranges from 0 to k-1(both inclusive) for i in range(n): for j in range(i): rem = (nums[i]+nums[j])%k dp[i][rem]=max(dp[i][rem], dp[j][rem]+1) # easy! BASE CASE:: just like LIS, every subsequence can start from that element itself, so for i in range(n): for ck in range(k): dp[i][ck]=1 # DONE!!! JUST PRINT THE MAX VALUE IN ENTIRE DP ARRAY!
@codingmohan
@codingmohan 2 ай бұрын
I think DP is not required at all. kzbin.info/www/bejne/jJDFh594lrebY9U
Collect Coins in a Tree | In Out DP Explained | Weekly Contest 338
1:08:58
отомстил?
00:56
История одного вокалиста
Рет қаралды 4,8 МЛН
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 35 МЛН
HAH Chaos in the Bathroom 🚽✨ Smart Tools for the Throne 😜
00:49
123 GO! Kevin
Рет қаралды 10 МЛН
The Best Programmer I Know • Daniel Terhorst-North • GOTO 2024
48:33
GOTO Conferences
Рет қаралды 34 М.
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 308 М.
3250. Find the Count of Monotonic Pairs I | Weekly Leetcode 410
20:00
Hybrid-Level Programming - Richard Feldman
51:26
Zig SHOWTIME
Рет қаралды 4,3 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 806 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 359 М.
отомстил?
00:56
История одного вокалиста
Рет қаралды 4,8 МЛН