-
Notifications
You must be signed in to change notification settings - Fork 19
/
🧩 tiktok_revision.txt
22 lines (20 loc) · 1.56 KB
/
🧩 tiktok_revision.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1. 🌟(New concept! Must do) Number of ways of cutting a pizza
- LOGIC: Main logic is just to understand how to create postSum, rest of the problem is basic DP!
- Postsum means from an index, we are checking the apples to right-lower part of 2d matrix starting from there
- This we can find by adding total apples from right and lower part
- But when we take lower part, it will overlap the right part and will give more apples (not correct answer)
- Hence we need to subtract Union of(lower and right part )- i.e [ind+1][jnd+1]
- Also we need to do + 1 if at current position we have an apple!
- .............
- Once above postSum matrix is done, now just do the question as per given condition and start cutting from each row and col
- But make sure to memoize as there will be multiple sub problem created
2. Umbrella Problem
- Problem is similar to coin change problem!
- Basic recursion and memoization
3. 🌟 (New Concept! Must do) Minimum increment to make array unique
- Sorting is the first step which should come to mind as we are concerned with sequence here
- After sorting, the major part is to understand we need to implement greedy
- Also! We can only + and no -
- Hence if at any point previous num is greater or equal means we are required to increment current +1 greater than previous
- (Think it this way - previous must have passed through current num as we are doing +1 always - that only when it's ==)
- Example - 1, 2, 2, 2, 3 - here -> 1, 2, 3, 4, (3) - 3 now knows as previous is 4, it's true that previous somewhere 3-4 must be there, hence just increment more than 4