Hi
Recently CSES added 100 new problems to their problemset. Here is the
solution to one those problems from the dynamic programming section.
https://cses.fi/problemset/task/2413/
The solution discussed in the video is O(N) per testcase and overall has a time complexity of O(N*T).
However it is possible to cache the results beforehand thus answering each query in O(1) and get an improved running time of O(N+T).
Here is the optimized code: https://cses.fi/paste/e643e2acd0c9278...
Do support the channel by hitting the subscribe button and giving a like :)
Super useful books for algo ds and programming fundamentals!
1. Introduction to Algorithms by Cormen: https://amzn.to/35AmQqu
2. The Algorithm Design Manual: https://amzn.to/2K9RGPq
3. Fundamentals of Data Structures in C++: https://amzn.to/2LCwIsN
4. Object-Oriented Programming by E Balagurusamy: https://amzn.to/2Xxmdtr
5. Head First Java: https://amzn.to/39kb44K
6. Cracking the coding interview: https://amzn.to/3iDOHLK
7. Database System concepts: https://amzn.to/3pisuFQ
8. Operating Systems: https://amzn.to/39fcmis
9. Discrete Mathematics: https://amzn.to/2MlgCE6
10. Compiler Design: https://amzn.to/3pkYvx2