├── README.md ├── Problem 2-Time Complexity.ipynb ├── Problem1.py ├── Problem 1- Generating Binary strings.ipynb └── Problem 8- Anagram Problem.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Competitive-Programming -------------------------------------------------------------------------------- /Problem 2-Time Complexity.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Find The Time Complexity" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 10, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "### What is the Time Complexity\n", 17 | "def Func(n):\n", 18 | " for i in range(1,n):\n", 19 | " j=i\n", 20 | " while j=97:\n", 136 | " if ord(str1[i])-32 not in dict:\n", 137 | " dict[ord(str1[i])-32] = 1\n", 138 | " else:\n", 139 | " dict[ord(str1[i])-32] = dict[ord(str1[i])-32] + 1\n", 140 | " else:\n", 141 | " if ord(str1[i]) not in dict:\n", 142 | " dict[ord(str1[i])] = 1\n", 143 | " else:\n", 144 | " dict[ord(str1[i])] = dict[ord(str1[i])] + 1\n", 145 | "\n", 146 | " for i in range(len(str2)):\n", 147 | " if ord(str2[i])<=122 and ord(str2[i])>=97:\n", 148 | " if ord(str2[i])-32 in dict:\n", 149 | " if dict[ord(str2[i])-32] != 0:\n", 150 | " dict[ord(str2[i])-32] = dict[ord(str2[i])-32] - 1\n", 151 | " else:\n", 152 | " return 0\n", 153 | " else:\n", 154 | " return 0\n", 155 | " else:\n", 156 | " if ord(str2[i]) in dict:\n", 157 | " if dict[ord(str2[i])] != 0:\n", 158 | " dict[ord(str2[i])] = dict[ord(str2[i])] - 1\n", 159 | " else:\n", 160 | " return 0\n", 161 | " else:\n", 162 | " return 0\n", 163 | "\n", 164 | " return 1\n", 165 | "\n", 166 | "\n", 167 | "\n", 168 | "str1 = input(\"Enter the first string\")\n", 169 | "str2 = input(\"Enter the second string\")\n", 170 | "if Anagram(str1,str2):\n", 171 | " print(\"Yes\")\n", 172 | "else:\n", 173 | " print(\"No\")\n", 174 | "\n", 175 | "\n", 176 | "\n" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 23, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "### Final Solution\n", 186 | "def anagram(str1,str2):\n", 187 | " group_letters={}\n", 188 | " for i in str1:\n", 189 | " if i in group_letters:\n", 190 | " group_letters[i]+=1\n", 191 | " else:\n", 192 | " group_letters[i]=1\n", 193 | " for i in str2:\n", 194 | " if i in group_letters:\n", 195 | " group_letters[i]-=1\n", 196 | " else:\n", 197 | " group_letters[i]=1\n", 198 | " for j in group_letters:\n", 199 | " if group_letters[j]!=0:\n", 200 | " return False\n", 201 | " return True" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 22, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "Enter the first string: Eleven plus two\n", 214 | "Enter the first string: twelve plus one\n", 215 | "The entered strings are anagram\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "string1=input(\"Enter the first string: \")\n", 221 | "string1=string1.replace(\" \",\"\").lower()\n", 222 | "string2=input(\"Enter the first string: \")\n", 223 | "string2=string2.replace(\" \",\"\").lower()\n", 224 | "var=anagram(string1,string2)\n", 225 | "if(var):\n", 226 | " print(\"The entered strings are anagram\")\n", 227 | "else:\n", 228 | " print(\"The entered strings are not anagram\")" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": {}, 234 | "source": [ 235 | "### Find all the anagrams from a list of words\n", 236 | "['cat', 'dog', 'tac', 'god', 'act']" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": null, 242 | "metadata": {}, 243 | "outputs": [], 244 | "source": [] 245 | } 246 | ], 247 | "metadata": { 248 | "kernelspec": { 249 | "display_name": "Python 3", 250 | "language": "python", 251 | "name": "python3" 252 | }, 253 | "language_info": { 254 | "codemirror_mode": { 255 | "name": "ipython", 256 | "version": 3 257 | }, 258 | "file_extension": ".py", 259 | "mimetype": "text/x-python", 260 | "name": "python", 261 | "nbconvert_exporter": "python", 262 | "pygments_lexer": "ipython3", 263 | "version": "3.7.7" 264 | } 265 | }, 266 | "nbformat": 4, 267 | "nbformat_minor": 4 268 | } 269 | --------------------------------------------------------------------------------