├── Shorts.docx ├── 9. Tree └── Tree.docx ├── 1. Array ├── Array.docx └── Prefix Sum.docx ├── 12. Graph ├── Graph.docx └── ~$Graph.docx ├── 7. Hashing └── Hashing.docx ├── 3. Stack + Queue ├── Stack.docx └── Stack.pdf ├── 5. Recursion ├── Recursion.pdf ├── RECURSION_QUES.docx ├── Recursion-notes.pdf └── ~$CURSION_QUES.docx ├── 4. Linked List ├── Linked list.pdf ├── Linked List.docx └── Linked List (easy).ipynb ├── 6. Backtracking └── Backtracking.pdf ├── 15. Heap + Priority Queue └── Heap.docx ├── 14. Binary Search └── Binary Search.docx ├── 13. Bit Manipulation └── Bit Manipulation.docx ├── 11. Dynamic Programming ├── Dynamic Programming.pdf ├── Dynamic Programming.docx ├── ~$namic Programming.docx ├── DP category-wise questions.docx ├── Dynamic Programming - temp.docx ├── ~$namic Programming - temp.docx ├── Dynamic Programming Atcoder.docx ├── Dynamic Programming - temp (Autosaved).docx └── ~$namic Programming - temp (Autosaved).docx └── 8. Sliding Window+ two pointer ├── Sliding Window.docx └── Two Pointers.docx /Shorts.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/Shorts.docx -------------------------------------------------------------------------------- /9. Tree/Tree.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/9. Tree/Tree.docx -------------------------------------------------------------------------------- /1. Array/Array.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/1. Array/Array.docx -------------------------------------------------------------------------------- /12. Graph/Graph.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/12. Graph/Graph.docx -------------------------------------------------------------------------------- /12. Graph/~$Graph.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/12. Graph/~$Graph.docx -------------------------------------------------------------------------------- /1. Array/Prefix Sum.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/1. Array/Prefix Sum.docx -------------------------------------------------------------------------------- /7. Hashing/Hashing.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/7. Hashing/Hashing.docx -------------------------------------------------------------------------------- /3. Stack + Queue/Stack.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/3. Stack + Queue/Stack.docx -------------------------------------------------------------------------------- /3. Stack + Queue/Stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/3. Stack + Queue/Stack.pdf -------------------------------------------------------------------------------- /5. Recursion/Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/5. Recursion/Recursion.pdf -------------------------------------------------------------------------------- /4. Linked List/Linked list.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/4. Linked List/Linked list.pdf -------------------------------------------------------------------------------- /4. Linked List/Linked List.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/4. Linked List/Linked List.docx -------------------------------------------------------------------------------- /5. Recursion/RECURSION_QUES.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/5. Recursion/RECURSION_QUES.docx -------------------------------------------------------------------------------- /5. Recursion/Recursion-notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/5. Recursion/Recursion-notes.pdf -------------------------------------------------------------------------------- /5. Recursion/~$CURSION_QUES.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/5. Recursion/~$CURSION_QUES.docx -------------------------------------------------------------------------------- /6. Backtracking/Backtracking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/6. Backtracking/Backtracking.pdf -------------------------------------------------------------------------------- /15. Heap + Priority Queue/Heap.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/15. Heap + Priority Queue/Heap.docx -------------------------------------------------------------------------------- /14. Binary Search/Binary Search.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/14. Binary Search/Binary Search.docx -------------------------------------------------------------------------------- /13. Bit Manipulation/Bit Manipulation.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/13. Bit Manipulation/Bit Manipulation.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/Dynamic Programming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/Dynamic Programming.pdf -------------------------------------------------------------------------------- /11. Dynamic Programming/Dynamic Programming.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/Dynamic Programming.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/~$namic Programming.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/~$namic Programming.docx -------------------------------------------------------------------------------- /8. Sliding Window+ two pointer/Sliding Window.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/8. Sliding Window+ two pointer/Sliding Window.docx -------------------------------------------------------------------------------- /8. Sliding Window+ two pointer/Two Pointers.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/8. Sliding Window+ two pointer/Two Pointers.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/DP category-wise questions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/DP category-wise questions.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/Dynamic Programming - temp.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/Dynamic Programming - temp.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/~$namic Programming - temp.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/~$namic Programming - temp.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/Dynamic Programming Atcoder.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/Dynamic Programming Atcoder.docx -------------------------------------------------------------------------------- /11. Dynamic Programming/Dynamic Programming - temp (Autosaved).docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/Dynamic Programming - temp (Autosaved).docx -------------------------------------------------------------------------------- /11. Dynamic Programming/~$namic Programming - temp (Autosaved).docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PALASH-BAJPAI/Data-Structures-And-Algorithms-Python-Notes/HEAD/11. Dynamic Programming/~$namic Programming - temp (Autosaved).docx -------------------------------------------------------------------------------- /4. Linked List/Linked List (easy).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d9b6ea6f", 6 | "metadata": {}, 7 | "source": [ 8 | "## Q1. Middle of the linked list\n", 9 | "Given the head of a singly linked list, return the middle node of the linked list.\n", 10 | "If there are two middle nodes, return the second middle node.\n", 11 | "\n", 12 | "Input: head = [1,2,3,4,5,6] \n", 13 | "Output: [4,5,6] \n", 14 | "Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.\n" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "id": "340b9f44", 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "class ListNode:\n", 25 | " def __init__(self, val=0, next=None):\n", 26 | " self.val = val\n", 27 | " self.next = next\n", 28 | "class Solution:\n", 29 | " def middleNode(self, head: ListNode) -> ListNode:\n", 30 | " fast=head\n", 31 | " slow=head\n", 32 | " while(fast and fast.next):\n", 33 | " fast=fast.next.next\n", 34 | " slow=slow.next\n", 35 | " \n", 36 | " return slow\n", 37 | " " 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "id": "81b214b7", 43 | "metadata": {}, 44 | "source": [ 45 | "## Q2. Reverse the linked list\n", 46 | "Given the head of a singly linked list, reverse the list, and return the reversed list." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "id": "452fbde0", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "\n", 57 | "#Recursively\n", 58 | "def reverseList(self, head: ListNode) -> ListNode: \n", 59 | " def sub(head):\n", 60 | " #base Case: 1->2->3-> for 3 next is None and hence it becomes new head\n", 61 | " if head is None:\n", 62 | " return None\n", 63 | " if head.next is None:\n", 64 | " return head\n", 65 | " \n", 66 | " #We need to keep track of new head\n", 67 | " newHead = sub(head.next)\n", 68 | " \n", 69 | " #Reverse the link\n", 70 | " head.next.next = head\n", 71 | " head.next= None\n", 72 | " \n", 73 | " return newHead\n", 74 | " \n", 75 | " return sub(head)\n", 76 | "\n", 77 | "\n", 78 | "#Iterative ( 2 pointer)\n", 79 | "def reverseList(self, head: ListNode) -> ListNode: \n", 80 | " #using 2 pointer\n", 81 | " curr,prev = head, None\n", 82 | " while(curr):\n", 83 | " nxt = curr.next\n", 84 | " curr.next = prev\n", 85 | " prev = curr\n", 86 | " curr = nxt\n", 87 | " return prev\n", 88 | " " 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "id": "7c3a4f83", 94 | "metadata": {}, 95 | "source": [ 96 | "## Q3. Merge Two Sorted Lists\n", 97 | "You are given the heads of two sorted linked lists list1 and list2. \n", 98 | "Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists. \n", 99 | "Return the head of the merged linked list.\n", 100 | "\n", 101 | "**Intuition** \n", 102 | "1. Make temp linkedList with head , and traverse it using t pointer.\n", 103 | "2. If value of l1 is less than l2 append l1.val to t and traverse t and l1.\n", 104 | "3. If value of l2 is less than l1 append l2.val to t and traverse t and l2.\n", 105 | "4. If any of them reach its end , append other list to t\n", 106 | "5. since head initially has 0 and all new values are appended after it, so return head.next" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "id": "2264ca81", 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "class ListNode:\n", 117 | " def __init__(self, val=0, next=None):\n", 118 | " self.val = val\n", 119 | " self.next = next\n", 120 | "class Solution:\n", 121 | " def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:\n", 122 | " a=ListNode()\n", 123 | " t=a\n", 124 | " while(l1 and l2):\n", 125 | " if l1.val < l2.val:\n", 126 | " t.next = ListNode(l1.val)\n", 127 | " l1 = l1.next\n", 128 | " elif l1.val >= l2.val:\n", 129 | " t.next = ListNode(l2.val)\n", 130 | " l2 = l2.next\n", 131 | " t = t.next\n", 132 | " \n", 133 | "\n", 134 | " if l1 is not None:\n", 135 | " t.next=l1\n", 136 | " if l2 is not None:\n", 137 | " t.next=l2\n", 138 | " \n", 139 | " return a.next " 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "id": "b696bad1", 145 | "metadata": {}, 146 | "source": [ 147 | "## Q4. Remove Linked List Elements \n", 148 | "Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.\n", 149 | "\n", 150 | "1. Input: head = [1,2,6,3,4,5,6], val = 6\n", 151 | " Output: [1,2,3,4,5] \n", 152 | "2. Input: head = [7,7,7,7], val = 7\n", 153 | " Output: []" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "id": "98550cfc", 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "class ListNode:\n", 164 | " def __init__(self, val=0, next=None):\n", 165 | " self.val = val\n", 166 | " self.next = next\n", 167 | "class Solution:\n", 168 | " def removeElements(self, head: ListNode, val: int) -> ListNode:\n", 169 | " if head is None: return head\n", 170 | " t=head\n", 171 | " \n", 172 | " #Don't traverse when u delete , since for [7,7,7,7] if we delete and traverse we reach from 7 at index 0 to 7 at index 2\n", 173 | " #and then won't be able to delete 7 of index 2\n", 174 | " \n", 175 | " while(t and t.next):\n", 176 | " if(t.next.val == val):\n", 177 | " t.next = t.next.next\n", 178 | " else:\n", 179 | " t=t.next\n", 180 | " \n", 181 | " return head.next if head.val == val else head" 182 | ] 183 | } 184 | ], 185 | "metadata": { 186 | "kernelspec": { 187 | "display_name": "Python 3", 188 | "language": "python", 189 | "name": "python3" 190 | }, 191 | "language_info": { 192 | "codemirror_mode": { 193 | "name": "ipython", 194 | "version": 3 195 | }, 196 | "file_extension": ".py", 197 | "mimetype": "text/x-python", 198 | "name": "python", 199 | "nbconvert_exporter": "python", 200 | "pygments_lexer": "ipython3", 201 | "version": "3.8.8" 202 | } 203 | }, 204 | "nbformat": 4, 205 | "nbformat_minor": 5 206 | } 207 | --------------------------------------------------------------------------------