Revise

You might also like

Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 32

Gas Station

Trapping Rain Water


Candy
Zigzag Conversion
11. Container With Most Water
30. Substring with Concatenation of All Words
48. Rotate Image
289. Game of Life
202. Happy Number
56. Merge Intervals
452. Minimum Number of Arrows to Burst Balloons
155. Min Stack
71. Simplify Path
92. Reverse Linked List II
19. Remove Nth Node From End of List
146. LRU Cache
226. Invert Binary Tree
101. Symmetric Tree
105. Construct Binary Tree from Preorder and Inorder Traversal
114. Flatten Binary Tree to Linked List
112. Path Sum
124. Binary Tree Maximum Path Sum
222. Count Complete Tree Nodes
236. Lowest Common Ancestor of a Binary Tree
130. Surrounded Regions
399. Evaluate Division
433. Minimum Genetic Mutation
211. Design Add and Search Words Data Structure
Permutations
427. Construct Quad Tree
148. Sort List
918. Maximum Sum Circular Subarray
IPO
Find K Pairs with Smallest Sums
295 Find the median from data stream
Factorial Trailing Zeroes
452. Minimum Number of Arrows to Burst Balloons
560. Subarray Sum Equals K
395. Longest Substring with At Least K Repeating Characters
673. Number of Longest Increasing Subsequence
1443. Minimum Time to Collect All Apples in a Tree
95. Unique Binary Search Trees II
In matrix prb simulate it and then convert into the code

took hint
stack is weak

was able to do it but with struggle

don’t mess with pointers


stupid learn something
was tricky but u r stupid
gadhe thoda jyada soch
whenever doing theroot to leaf question always check root->left==NULL and root->right==NULL

if you want to move from string to another string bfs should be used
Check

Box 9
Check

Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Check
Box 9
Problem
1187. Make Array Strictly Increasing
560. Subarray Sum Equals K
395. Longest Substring with At Least K Repeating Characters
673. Number of Longest Increasing Subsequence
95. Unique Binary Search Trees II
2808. Minimum Seconds to Equalize a Circular Array
2812. Find the Safest Path in a Grid
2811. Check if it is Possible to Split Array
1631. Path With Minimum Effort
920. Number of Music Playlists
240. Search a 2D Matrix II
2541. Minimum Operations to Make Array Equal II
1615. Maximal Network Rank
2369. Check if There is a Valid Partition For The Array
239. Sliding Window Maximum
542. 01 Matrix
767. Reorganize String
Rearrange string k distance apart
2707. Extra Characters in a String
2366. Minimum Replacements to Sort the Array
338. Counting Bits
81. Search in Rotated Sorted Array II
1203. Sort Items by Groups Respecting Dependencies
1326. Minimum Number of Taps to Open to Water a Garden
2799. Count Complete Subarrays in an Array
2848. Points That Intersect With Cars
1854. Maximum Population Year
731. My Calendar II
Remove Interval(coding ninjas)`
57. Insert Interval
1893. Check if All the Integers in a Range Are Covered
Meeting Rooms(interviewbit)
732. My Calendar III
Meetings II(coding ninjas)
1851. Minimum Interval to Include Each Query
2251. Number of Flowers in Full Bloom
1589. Maximum Sum Obtained of Any Permutation
1109. Corporate Flight Bookings
1943. Describe the Painting
646. Maximum Length of Pair Chain
435. Non-overlapping Intervals
452. Minimum Number of Arrows to Burst Balloons
1282. Group the People Given the Group Size They Belong To
1647. Minimum Deletions to Make Character Frequencies Unique
135. Candy
1584. Min Cost to Connect All Points
778. Swim in Rising Water
847. Shortest Path Visiting All Nodes
287. Find the Duplicate Number
1658. Minimum Operations to Reduce X to Zero
4. Median of Two Sorted Arrays
1048. Longest String Chain
799. Champagne Tower
316. Remove Duplicate Letters
215. Kth Largest Element in an Array
880. Decoded String at Index
2038. Remove Colored Pieces if Both Neighbors are the Same Color
456. 132 Pattern
343. Integer Break
1458. Max Dot Product of Two Subsequences
1095. Find in Mountain Array
2009. Minimum Number of Operations to Make Array Continuous
1420. Build Array Where You Can Find The Maximum Exactly K Comparisons
2742. Painting the Walls
332. Reconstruct Itinerary
1269. Number of Ways to Stay in the Same Place After Some Steps
1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
2542. Maximum Subsequence Score
1383. Maximum Performance of a Team
119. Pascal's Triangle II
2246. Longest Path With Different Adjacent Characters
2050. Parallel Courses III
341. Flatten Nested List Iterator
1793. Maximum Score of a Good Subarray
515. Find Largest Value in Each Tree Row
823. Binary Trees With Factors
1356. Sort Integers by The Number of 1 Bits
1220. Count Vowels Permutation
2433. Find The Original Array of Prefix Xor
2265. Count Nodes Equal to Average of Subtree
779. K-th Symbol in Grammar
1425. Constrained Subsequence Sum
1535. Find the Winner of an Array Game
1845. Seat Reservation Manager
1921. Eliminate Maximum Number of Monsters
1759. Count Number of Homogenous Substrings
2923. Find Champion I
2924. Find Champion II
1361. Validate Binary Tree Nodes
2785. Sort Vowels in a String
1846. Maximum Element After Decreasing and Rearranging
1473. Paint House III
815. Bus Routes
1877. Minimize Maximum Pair Sum in Array
1980. Find Unique Binary String
1838. Frequency of the Most Frequent Element
1887. Reduction Operations to Make the Array Elements Equal
2391. Minimum Amount of Time to Collect Garbage
1814. Count Nice Pairs in an Array
1424. Diagonal Traverse II
1630. Arithmetic Subarrays
1685. Sum of Absolute Differences in a Sorted Array
2410. Maximum Matching of Players With Trainers
number-of-inversions(coding ninjas)
493. Reverse Pairs
2426. Number of Pairs Satisfying Inequality
Find Leaves of Binary Tree
1727. Largest Submatrix With Rearrangements
935. Knight Dialer
2147. Number of Ways to Divide a Long Corridor
304. Range Sum Query 2D - Immutable
1266. Minimum Time Visiting All Points
1743. Restore the Array From Adjacent Pairs
1798. Maximum Number of Consecutive Values You Can Make
2952. Minimum Number of Coins to be Added
2947. Count Beautiful Substrings I
1582. Special Positions in a Binary Matrix
2482. Difference Between Ones and Zeros in Row and Column
31. Next Permutation
75. Sort Colors
48. Rotate Image
88. Merge Sorted Array
287. Find the Duplicate Number
229. Majority Element II
18. 4Sum
128. Longest Consecutive Sequence
Subarray with given XOR
1496. Path Crossing
Flattening a Linked List(gfg)
1335. Minimum Difficulty of a Job Schedule
1578. Minimum Time to Make Rope Colorful
2610. Convert an Array Into a 2D Array With Conditions
Job Sequencing Problem(gfg)
300. Longest Increasing Subsequence
1235. Maximum Profit in Job Scheduling
90. Subsets II
938. Range Sum of BST
2385. Amount of Time for Binary Tree to Be Infected
131. Palindrome Partitioning
2225. Find Players With Zero or One Losses
1657. Determine if Two Strings Are Close
380. Insert Delete GetRandom O(1)
60. Permutation Sequence
931. Minimum Falling Path Sum
M Coloring Problem
1457. Pseudo-Palindromic Paths in a Binary Tree
Allocate Books(InterviewBit)
1074. Number of Submatrices That Sum to Target
368. Largest Divisible Subset
https://www.interviewbit.com/problems/maximum-sum-combinations/
23. Merge k Sorted Lists
155. Min Stack
1463. Cherry Pickup II
The Celebrity Problem
295. Find Median from Data Stream
997. Find the Town Judge
645. Set Mismatch
2092. Find All People With Secret
416. Partition Equal Subset Sum
84. Largest Rectangle in Histogram
14. Longest Common Prefix
523. Continuous Subarray Sum
https://leetcode.com/problems/bag-of-tokens/
977. Squares of a Sorted Array
1750. Minimum Length of String After Deleting Similar Ends
28. Find the Index of the First Occurrence in a String
165. Compare Version Numbers
686. Repeated String Match
Bottom View Of Binary Tree
525. Contiguous Array
Boundary Traversal of Binary Tree
116. Populating Next Right Pointers in Each Node
1008. Construct Binary Search Tree from Preorder Traversal
98. Validate Binary Search Tree
Predecessor And Successor In BST
41. First Missing Positive
2444. Count Subarrays With Fixed Bounds
2962. Count Subarrays Where Max Element Appears at Least K Times
1373. Maximum Sum BST in Binary Tree
Binary Tree to DLL(gfg)
678. Valid Parenthesis String
785. Is Graph Bipartite?
85. Maximal Rectangle
950. Reveal Cards In Increasing Order
1092. Shortest Common Supersequence
310. Minimum Height Trees
752. Open the Lock
2370. Longest Ideal Subsequence
514. Freedom Trail
834. Sum of Distances in Tree
Egg Dropping Puzzle(gfg)
Palindromic Partitioning
Longest String with All Prefixes
Implement Trie-2
Count Distinct Substrings
421. Maximum XOR of Two Numbers in an Array
1707. Maximum XOR With an Element From Array
506. Relative Ranks
786. K-th Smallest Prime Fraction
857. Minimum Cost to Hire K Workers
861. Score After Flipping Matrix
3068. Find the Maximum Sum of Node Values
2812. Find the Safest Path in a Grid
1208. Get Equal Substrings Within Budget
1404. Number of Steps to Reduce a Number in Binary Representation to One
552. Student Attendance Record II
1442. Count Triplets That Can Form Two Arrays of Equal XOR
2597. The Number of Beautiful Subsets
673. Number of Longest Increasing Subsequence
3169. Count Days Without Meetings
846. Hand of Straights
945. Minimum Increment to Make Array Unique
3186. Maximum Total Damage With Spell Casting
826. Most Profit Assigning Work
1552. Magnetic Force Between Two Balls
1052. Grumpy Bookstore Owner
1248. Count Number of Nice Subarrays
1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
3191. Minimum Operations to Make Binary Array Elements Equal to One I
3192. Minimum Operations to Make Binary Array Elements Equal to One II
995. Minimum Number of K Consecutive Bit Flips
1038. Binary Search Tree to Greater Sum Tree
1382. Balance a Binary Search Tree
152. Maximum Product Subarray
2285. Maximum Total Importance of Roads
1579. Remove Max Number of Edges to Keep Graph Fully Traversable
908. Smallest Range I
Category Pattern

Array sliding window

Tree dfs+bfs
Tree permutation(divide n conquer)
Array circular
Grid bfs+bs
Array partition
Grid Dijikstra
dp Multiply
Grid bs
Array Equal
Graph indegree
Array dp
Array sliding window
Grid Bfs
String heap
String heap
String dp
Array Math
Bit
Array bs
Graph topo sort
Array Sweep Line
Array sliding window
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
interval Sweep Line
Array hash
Array hash
Array Greedy
Points Kruskal/Prims
Graph Dijikstra
Graph Bfs
Array floyd warshall algorithm
Array prefix

Array bs
String dp
simulation
String monotonic stack
Array quick select
String modulo
String Greedy
Array monotonic stack
dp
Array dp
Array bs
Array bs
Array dp
Array dp
Array dfs
dp
Graph MST
Array heap
Array heap
Array
Graph
Graph topo sort
Design queue
Array monotonic stack
Tree bfs
Array dp
Array Bit
dp dp
bit
Tree dfs
bs bs
Array dp
Array simulation
Design heap
Array sort
String substring
Array topo sort
Array topo sort
Tree dfs/bfs
String sort
Array Greedy
Array dp
Graph bfs
Array sorting
Array Bit
Array sliding window
Array sorting
Array prefix
Array math
Array map
Array sorting
Array prefix
Array sorting
Array merge sort
Array merge sort
Array merge sort
Tree dfs
matrix sorting
dp
String Combinatrics
matrix prefix
Array Math
Tree dfs/bfs
Array weird
Array weird
String brute force
matrix prefix
matrix prefix
Array weird
Array dutch flag algo
matrix rotate
Array weird
Array floyd warshall algorithm
Array weird
Array 2 ptr
Array hash
Array prefix
String
Linked List recursion
Array dp
Array
Array freq cntr
Array Greedy
Array bs
Array dp+bs
Array backtracking
Tree inorder
Tree bfs
Array recursion
Array topo sort
Array hash
simulation hash
String recursion
matrix dp
Graph backtracking
Tree preorder
BS
matrix prefix
Array dp
Array heap
Linked List common
Array stack
matrix dp
graph stack
simulation 2 heap
Array topo sort
Array bit
Array DSU
Array dp
Array monotonic queue
Array string
Array hash
Array 2 ptr
Array
String 2 ptr
String kmp
String 2 ptr
String kmp
Tree Vertical order traversal
Array prefix
Tree weird
Tree dfs
Tree dfs
Tree dfs
Tree
Array cycle sort
Array sliding window
Array sliding window
Tree dfs
Tree inorder
String stack
Tree color
matrix monotonic stack
Array queue
Array dp
Tree topo sort
Tree BFS
String DP
String dp
Tree dfs
dp dp
dp front partition
Trie
Trie
Trie
Trie
Trie
Array heap
Array heap
Array heap
matrix bit
Tree Sorting
Graph queue + bs
Array sliding window
String bit
dp
bit
Array LIS+dp
Array LIS
interval line sweep
Array map
Array sorting
Array dp
Array bs
Array bs
Array sliding window
Array sliding window
Array sliding window
Array Greedy
Array Greedy
Array Greedy
Array Morris Postorder Traversal
Tree inorder
Array simulation
Tree topo sort
Tree DSU
Array Math
subpattern subpattern2 Another Pattern Same

atmost k-atmost k-1

LIS
caltan series

1
1

partition
heap deque

2
queue 2
heap

dp
subarray
3
3
3
6
6
3

3
3
bs 7
bs 7
Sorting

Sorting 5
Sorting 5

greedy
4

Predecessor

lcs

LIS
knapsack

kruskal
greedy 8
greedy 8

stack
greedy

recursion
heap
bfs

2 ptr
Binary Index Tree 9
Binary Index Tree 9
Binary Index Tree 9

dp

10
10

partition
bit

linear

bfs

z function

11
11

3 ptr
subsequence

LIS

heap
heap deque
Sorting
String
Always check if leading and trailing space
check if its alphabet , number , special characters
use function like erase, substr
char to int ---> (s[i]-'0'), atoi,
check if space->isspace()
isdigit,
tolower(), toupper(), islower(), isupper()
to_string(number)

Rabin karp
Z function
stringstream
Basic methods are:
1. clear()- To clear the stream.
2. str()- To get and set string object whose content is present in the stream.

3. operator <<- Add a string to the stringstream object.

4. operator >>- Read something from the stringstream object.

stringstream s(str);
string word;
int count = 0;
while (s >> word)

count++;

return count;

split
istringstream iss(sentence);
string temp;
while(getline(iss,s,' '))

copy(vec.begin(), vec.end(), ostream_iterator<string>(res, delim));

regex_replace(command, regex("\\(\\)+"),"o");
refer leetcode 1678
Graph
multisource bfs

cycle detection
undirected graph--> only visited array
directed graph-->visited and inrecursion array
Subarray
if question ask about subarray sum equal to k use hashmap sliding window wont work
for negative number sliding window won't work
sliding window will work if we need to find subarray sum upto k
To Do->523. Continuous Subarray Sum

Vector

Store increasing sequence


Assigns to every element in the range [first, last] successive values of val, as if incremented
with ++val after each element is written.
iota(numbers, numbers + 11, st);

if kth smallest/largest comes use heap

stable_partition()
The stable_partition( ) algorithm arranges the sequence defined by start and end such that all
elements for which the predicate specified by pfn returns true come before those for which the
predicate returns false. The partitioning is stable. This means that the relative ordering of the
sequence is preserved.
stable_partition(v.begin(), v.end(), [](int n) {return n>0; });

{ 6, 9, 0, 1, 2, 7, 5, 8, 0 }
6 9 1 2 7 5 8 0 0

Where ever u find your output depends on Increasing followed by decreasing and again repeated or vice versa then use peak & valley
2 ptr
if the code only selects one of the two ptr then put condition i<=j in while loop

e peak & valley


Binary tree
Morris Traversal preorder, inorder
left/right view
vertical order traversal
a heap is always a complete binary tree.

In-order Morris Traversal:


1st case: if left is null, print current node and go right
2nd case: before going left, make right most node on left subtree connected to current node, then go left
3rd case: if thread is already pointed to current node, then remove the th
Show less
Graph
Graph with odd length cycle is never bipartitie

Dijikstra
Single source single destination shortest path

Bellman Ford
Single source multiple destination shortest path
works for negative edges
ee connected to current node, then go left
Floyd Warshall
Multiple Source to multiple destination shortest path

You might also like