Leetcode #1423: Maximum Points You Can Obtain from Cards

You can’t choose the 2nd element from the front unless you have chosen the first one. Similarly, you can’t choose the 2nd element from the back unless you have chosen the last one already. You want to choose a total of K numbers. There are limited number of ways in which you can choose those numbers given the constraints … … More Leetcode #1423: Maximum Points You Can Obtain from Cards

Leetcode #1443: Minimum Time to Collect All Apples in a Tree

Whenever you are at a node, say p, you will collect all apples in p’s subtree before returning back to the original root. This will avoid traveling the same path multiple times. …. Because you have the list of edges, construct a better representation – adjacency list – of the tree. … More Leetcode #1443: Minimum Time to Collect All Apples in a Tree

Leetcode #1472: Design Browser History

Thought Process – Say you visit a website A. Then got to B, C, and D in the order. If you go back, you will be at C. Go back further, you will be at B, and if you go back again, you will reach A.
Thing to note is that the order of websites totally reversed when going back compared to the order in which you visited them. So certainly we need a stack data structure for the back operation which will store the history. … More Leetcode #1472: Design Browser History