|
14 | 14 | - [Binary Search](#binary-search)
|
15 | 15 | - [Linked List](#linked-list)
|
16 | 16 | - [Trees](#trees)
|
| 17 | +- [Priority Queue](#priority-queue) |
17 | 18 | - [Hints](#hints)
|
18 | 19 |
|
19 | 20 | ## Arrays & Hashing
|
|
97 | 98 | | ------- | ---------- | --------------- | ---------------- | -------------- |
|
98 | 99 | | [94. Binary Tree Inorder Traversal](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/BinaryTreeInorderTraversal.cs) | Easy | O(n) | O(n) | - For iterative approach use stack (while stack.Any || currNode != null) <br /> - If currNode != null - push node to stack, go left <br /> - If currNode == null - get prevNode from stack, add value to result,go the prevNode.right |
|
99 | 100 | | [100. Same Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/SameTree.cs) | Easy | O(n) | O(n) | Check that values of trees nodes are equal, use recursion to repeat for each node (left and right) |
|
| 101 | +| [101. Symmetric Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/SymmetricTree.cs) | Easy | O(n) | O(h) | - Start to check from root left and right children <br /> - If both null - return true, if onle one is null - false, then if left.val != right.val - return false <br /> - Then we need to check node1.left with node2.right and node1.right with node2.left (repeat recursively) | |
100 | 102 | | [104. Maximum Depth of Binary Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/MaximumDepthOfBinaryTree.cs) | Easy | O(n) | O(n) | - DFS iterative - use stack to store nodes and depth <br /> - BFS iterative - use queue to count levels <br /> - Recursion - return Max of recursive calls of left and right children + 1 |
|
101 | 103 | | [108. Convert Sorted Array to Binary Search Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/ConvertSortedArrayToBinarySearchTree.cs) | Easy | O(n) | O(log(n)) | - Use **Divide and Conquer** approach: mid value - node value, left subarray - left subtree, right subarray - right subtree <br /> - Use recursion for both left and right subtrees |
|
102 | 104 | | [110. Balanced Binary Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/MaximumDepthOfBinaryTree.cs) | Easy | O(n) | O(n) | - Find max depth of left and right children <br /> - Difference should be <= 1 <br /> - Repeat recursively for each node, if diff is invalid - mark result flag|
|
|
108 | 110 | | [572. Subtree of Another Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/SubtreeOfAnotherTree.cs) | Easy | O(nm) | O(nm) | For each node where value = subroot.value we need to check if it is SameTree(problem 100) or node.left/node.right is SameTree as subroot |
|
109 | 111 | | [606. Construct String from Binary Tree](AlgorithmsAndDS/AlgorithmsAndDS/Trees/Easy/ConstructStringFromBinaryTree.cs) | Easy | O(n) | O(n) | Use DFS to recursively build string with PreOrder Traversal |
|
110 | 112 |
|
| 113 | +## Priority Queue |
| 114 | + |
| 115 | +| Problem | Complexity | Time Complexity | Space Complexity | Solution Hints | |
| 116 | +| ------- | ---------- | --------------- | ---------------- | -------------- | |
| 117 | +| [703. Kth Largest Element in a Stream](AlgorithmsAndDS/AlgorithmsAndDS/PriorityQueue/Easy/KthLargestElementInStream.cs) | Easy | O(log(n)) | O(k) | - Put elements to MinHeap always maintaining k elements <br /> - During adding peek element from queue and compare with value, dequeue and enqueue new value if it is greater | |
| 118 | +| [1046. Last Stone Weight](AlgorithmsAndDS/AlgorithmsAndDS/PriorityQueue/Easy/LastStoneWeight.cs) | Easy | O(nlog(n)) | O(n) | - Put all elements into a priority queue <br /> - Pop out the two biggest, push back the difference, until there are no more two elements left | |
| 119 | + |
111 | 120 | ## Hints
|
112 | 121 |
|
113 | 122 | - Find range sum/sum in array - prefix/postfix sum of array
|
|
0 commit comments