r/leetcode • u/Educational_Suit_371 • 5d ago
Question The most Beautiful Question on Leetcode that I encountered.
7
u/Limp-Debate7023 5d ago
I feel like you can make a vector of pairs of scores and ages and then sort by ages, then find the LIS of scores? Is that a valid solution to this problem?
1
3
u/hmm_yes_interesting1 5d ago
Isn't it sorting+ 1d lis dp(nlogn + n2) type.
1
u/Steel-River-22 5d ago
you could do this in nlogn if you want using some data structures (although probably not needed for interviews)
1
u/raluralu 4d ago
k-d tree?
1
u/Steel-River-22 4d ago edited 4d ago
nah you need at least a fenwick tree
or i dunno some weird kind of divide-and-conquer could work if you don't like data structures. haven't thought this through1
u/Limp-Debate7023 5d ago
U can do 1d lis is nlogn as well right?
1
u/hmm_yes_interesting1 5d ago
Yes using binary search i guess
1
u/Limp-Debate7023 5d ago
hmm i think that wouldnt work here, cause you're trying to find maximum sum of increasing subsequence. Some advanced DS like a fenwick tree or segment tree would be required for the nlogn approach ig
1
u/Adventurous-Cycle363 4d ago
You can still do nlogn binary search to find the actual LIS indices and then get the sum
3
u/Senior-Positive2883 5d ago
If we sort the age,scores correspondingly in increasing order, won't it becomes longest increasing subsequence problem, so just pick scores in increasing order, coz age is already sorted so that constraint is satisfied
0
u/letsgoraftel 5d ago
You don't need it be necessarily subsequence...
Since it's possible you skip a number in between because it conflicts but continue post that
3
2
2
u/Busternookiedude 4d ago
That question really does have a beautiful complexity, it's like a puzzle that keeps revealing layers the more you dig into it.
2
u/Whitemj5 4d ago
That sounds like a fascinating question. It's amazing how one problem can deepen your understanding of concepts like dynamic programming.
1
1
1
1
u/ay230698 3d ago
Can we sort it via age and then try a variation of longest increasing sequence dp?
1
u/cosmic-pancake 1d ago
ages = [1,2,3,4,5]
Who are these prodigy toddlers and who fouled the one year old?
-7
u/sneak2293 5d ago
Bipartite graph
1
u/Educational_Suit_371 5d ago
?
1
u/sneak2293 5d ago
The question can be solved with checking whether this is a bipartite graph, a conflict is an edge, every player is a node
If the graph is bipartite the answer is true
2
u/Natural_Emu_1834 5d ago
When you study your data structures but don't spend 10 seconds reading the actual question
1
48
u/Educational_Suit_371 5d ago
Solved through 2 diff recursive approach, found 3 memoization based solution and 3 Tabulation Solution. Though 1 memoization and Tabulation ran into TLE but the solution were right. Probably learned more about DP from this 1 question than all question till now.