Leetcode 70. Climbing Stairs

Now that we know 3rd step can be reached directly from 1st and 2nd, what will be the number of ways in which we can reach the step 3? It would be all the ways in which we can reach the step 1 (because we can always take 2 steps from here to reach the step 3) + the number of ways in which we can reach the step 2 (because we can always take 1 more step to reach the step 3). … More Leetcode 70. Climbing Stairs

Leetcode #1529: Bulb Switcher IV

Certainly, a “Flip” is a must when the current status of a bulb at index i and it’s the target status are not the same.

Initially all bulbs are OFF i.e. 0 and when a bulb at index i is flipped, every bulb after (in the right -> direction) that bulb gets flipped. So it only makes sense to start getting the status of the bulbs correct int the left to right order. … More Leetcode #1529: Bulb Switcher IV

Leetcode #1465: Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

So the only task for us is to find what would be the height and width of each piece after all cuts and then find the piece with maximum height and width. Each cut in the cake, divides the cake into pieces with certain height and certain width. We want to maximize the area … … More Leetcode #1465: Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

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