├── .gitattributes ├── .github └── workflows │ └── black.yml ├── .gitignore ├── BasicDataTypes ├── Findingthepercentage.py ├── FindtheSecondLargestNumber.py ├── ListComprehensions.py ├── Lists.py ├── NestedLists.py └── Tuples.py ├── BuiltIns ├── AnyorAll.py ├── AthleteSort.py ├── Input.py ├── PythonEvaluation.py ├── Zipped.py └── ginortS.py ├── Classes ├── Class2FindtheTorsionalAngle.py └── ClassesDealingwithComplexNumbers.py ├── ClosuresandDecorators ├── Decorators2NameDirectory.py └── StandardizeMobileNumberUsingDecorators.py ├── Collections ├── CollectionsOrderedDict.py ├── Collectionsdeque.py ├── Collectionsnamedtuple.py ├── DefaultDictTutorial.py ├── MostCommon.py ├── PilingUp.py ├── WordOrder.py └── collectionsCounter.py ├── DateandTime ├── CalendarModule.py └── TimeDelta.py ├── Debugging ├── DefaultArguments.py └── WordsScore.py ├── ErrorsandExceptions ├── Exceptions.py └── IncorrectRegex.py ├── HackerrankUtility ├── Hackerrank_Solution_Blank_File_Creator.py ├── Hackerrank_Solution_Lister.py ├── js_code.txt ├── python_info.txt └── solution_list.html ├── Hackerrank_Python_Domain.png ├── Hackerrank_Python_Domain_old.png ├── Introduction ├── ArithmeticOperators.py ├── Loops.py ├── PrintFunction.py ├── PythonDivision.py ├── PythonIfElse.py ├── SayHelloWorldWithPython.py └── Writeafunction.py ├── Itertools ├── CompresstheString.py ├── IterablesandIterators.py ├── MaximizeIt.py ├── itertoolscombinations.py ├── itertoolscombinations_with_replacement.py ├── itertoolspermutations.py └── itertoolsproduct.py ├── Math ├── FindAngleMBC.py ├── IntegersComeInAllSizes.py ├── ModDivmod.py ├── PolarCoordinates.py ├── PowerModPower.py ├── TriangleQuest.py └── TriangleQuest2.py ├── Numpy ├── ArrayMathematics.py ├── Arrays.py ├── Concatenate.py ├── DotandCross.py ├── EyeandIdentity.py ├── FloorCeilandRint.py ├── InnerandOuter.py ├── LinearAlgebra.py ├── MeanVarandStd.py ├── MinandMax.py ├── Polynomials.py ├── ShapeandReshape.py ├── SumandProd.py ├── TransposeandFlatten.py └── ZerosandOnes.py ├── PythonFunctionals ├── MapandLambdaFunction.py ├── ReduceFunction.py └── ValidatingEmailAddressesWithaFilter.py ├── RegexandParsing ├── DetectFloatingPointNumbers.py ├── DetectHTMLTagsAttributesandAttributeValues.py ├── GroupGroupsampGroupdict.py ├── HTMLParserPart1.py ├── HTMLParserPart2.py ├── HexColorCode.py ├── MatrixScript.py ├── RefindallampRefinditer.py ├── RegexSubstitution.py ├── Resplit.py ├── RestartampReend.py ├── ValidatingCreditCardNumbers.py ├── ValidatingPostalCodes.py ├── ValidatingRomanNumerals.py ├── ValidatingUID.py ├── ValidatingandParsingEmailAddresses.py └── Validatingphonenumbers.py ├── Sets ├── CheckStrictSuperset.py ├── CheckSubset.py ├── IntroductiontoSets.py ├── NoIdea.py ├── SetMutations.py ├── Setadd.py ├── SetdifferenceOperation.py ├── Setdiscardremoveamppop.py ├── SetintersectionOperation.py ├── Setsymmetric_differenceOperation.py ├── SetunionOperation.py ├── SymmetricDifference.py └── TheCaptainsRoom.py ├── Strings ├── AlphabetRangoli.py ├── Capitalize.py ├── DesignerDoorMat.py ├── Findastring.py ├── MergeTools ├── Mutations.py ├── StringFormatting.py ├── StringSplitandJoin.py ├── StringValidators.py ├── TextAlignment.py ├── TextWrap.py ├── TheMinionGame.py ├── WhatsYourName.py └── sWAPcASE.py ├── XML ├── XML1FindtheScore.py └── XML2FindtheMaximumDepth.py └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/workflows/black.yml: -------------------------------------------------------------------------------- 1 | name: Black 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | python-version: ["3.10"] 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Set up Python ${{ matrix.python-version }} 21 | uses: actions/setup-python@v3 22 | with: 23 | python-version: ${{ matrix.python-version }} 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | pip install black 28 | - name: Format all py files using black 29 | run: | 30 | black $(git ls-files '*.py') 31 | - name: Commit changes 32 | run: | 33 | git config --local user.email "action@github.com" 34 | git config --local user.name "GitHub Action" 35 | git add . 36 | git diff-index --quiet HEAD || git commit -m "Format Python code with Black" 37 | - name: Push changes 38 | run: | 39 | git push origin master 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | # Compiled python modules. 50 | *.pyc 51 | 52 | # Setuptools distribution folder. 53 | /dist/ 54 | 55 | # Python egg metadata, regenerated from source files by setuptools. 56 | /*.egg-info 57 | /*.egg 58 | 59 | # Ide preference 60 | /.idea 61 | /webapp/.idea/ 62 | /webapp/.idea/* 63 | .idea 64 | *.idea 65 | .eslintcache 66 | .eslintrc.json 67 | .vscode/ 68 | 69 | # Python Cache 70 | /__pycache__ 71 | 72 | # Virtual environments 73 | /venv/ 74 | /venv/* 75 | .env.local 76 | .env.development.local 77 | .env.test.local 78 | .env.production.local 79 | -------------------------------------------------------------------------------- /BasicDataTypes/Findingthepercentage.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Finding the percentage 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Updated : 06 February 2023 8 | Problem : https://www.hackerrank.com/challenges/finding-the-percentage/problem 9 | """ 10 | 11 | if __name__ == "__main__": 12 | n = int(input()) 13 | student_marks = {} 14 | for _ in range(n): 15 | name, *line = input().split() 16 | scores = list(map(float, line)) 17 | student_marks[name] = scores 18 | query_name = input() 19 | avg_score = sum(student_marks[query_name]) / len(student_marks[query_name]) 20 | print(f"{avg_score:.2f}") 21 | -------------------------------------------------------------------------------- /BasicDataTypes/FindtheSecondLargestNumber.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Find the Runner-Up Score! 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | n = int(input()) 12 | arr = map(int, input().split()) 13 | print(sorted(set(arr), reverse=True)[1]) 14 | -------------------------------------------------------------------------------- /BasicDataTypes/ListComprehensions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : List Comprehensions 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/list-comprehensions/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | x = int(input()) 12 | y = int(input()) 13 | z = int(input()) 14 | n = int(input()) 15 | ar = [ 16 | [i, j, k] 17 | for i in range(x + 1) 18 | for j in range(y + 1) 19 | for k in range(z + 1) 20 | if i + j + k != n 21 | ] 22 | print(ar) 23 | -------------------------------------------------------------------------------- /BasicDataTypes/Lists.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Lists 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Updated : 06 February 2023 8 | Problem : https://www.hackerrank.com/challenges/python-lists/problem 9 | """ 10 | 11 | if __name__ == "__main__": 12 | N = int(input()) 13 | ar = [] 14 | for _ in range(N): 15 | command_args = input().strip().split(" ") 16 | cmd = command_args[0] 17 | if cmd == "print": 18 | print(ar) 19 | elif cmd == "sort": 20 | ar.sort() 21 | elif cmd == "reverse": 22 | ar.reverse() 23 | elif cmd == "pop": 24 | ar.pop() 25 | elif cmd == "remove": 26 | val = int(command_args[1]) 27 | ar.remove(val) 28 | elif cmd == "append": 29 | val = int(command_args[1]) 30 | ar.append(val) 31 | elif cmd == "insert": 32 | pos = int(command_args[1]) 33 | val = int(command_args[2]) 34 | ar.insert(pos, val) 35 | -------------------------------------------------------------------------------- /BasicDataTypes/NestedLists.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Nested Lists 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/nested-list/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | students = [] 12 | scores = [] 13 | for _ in range(int(input())): 14 | name = input() 15 | score = float(input()) 16 | student = [name, score] 17 | students.append(student) 18 | scores.append(score) 19 | second_min_score = sorted(set(scores))[1] 20 | student_names = sorted( 21 | [student[0] for student in students if student[1] == second_min_score] 22 | ) 23 | print("\n".join(student_names)) 24 | -------------------------------------------------------------------------------- /BasicDataTypes/Tuples.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Tuples 3 | Subdomain : Data Types 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/python-tuples/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | n = int(input()) 12 | integer_list = map(int, input().split()) 13 | t = tuple(integer_list) 14 | print(hash(t)) 15 | -------------------------------------------------------------------------------- /BuiltIns/AnyorAll.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Any or All 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Updater : Imtiaz Ahmed 7 | Created : 15 July 2016 8 | Updated : 29 August 2022 9 | Problem : https://www.hackerrank.com/challenges/any-or-all/problem 10 | """ 11 | 12 | n = input() 13 | ar = input().split() 14 | print(all(int(i) > 0 for i in ar) and any(i == i[::-1] for i in ar)) 15 | -------------------------------------------------------------------------------- /BuiltIns/AthleteSort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Athlete Sort 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Atharva Shah 6 | Updater : Imtiaz Ahmed 7 | Created : 3 April 2021 8 | Updated : 30 August 2022 9 | Problem : https://www.hackerrank.com/challenges/python-sort-sort/problem 10 | """ 11 | 12 | if __name__ == "__main__": 13 | n, m = map(int, input().split()) 14 | 15 | arr = [] 16 | 17 | for _ in range(n): 18 | arr.append(list(map(int, input().rstrip().split()))) 19 | 20 | k = int(input()) 21 | 22 | for i in sorted(arr, key=lambda x: x[k]): 23 | print(*i) 24 | -------------------------------------------------------------------------------- /BuiltIns/Input.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Input() 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 3 April 2021 8 | Problem : https://www.hackerrank.com/challenges/input/problem 9 | """ 10 | 11 | if __name__ == "__main__": 12 | x, k = map(int, input().strip().split()) 13 | equation = input().strip() 14 | print(eval(equation) == k) 15 | -------------------------------------------------------------------------------- /BuiltIns/PythonEvaluation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Python Evaluation 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-eval/problem 8 | """ 9 | 10 | eval(input()) 11 | -------------------------------------------------------------------------------- /BuiltIns/Zipped.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Zipped! 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Updater : Imtiaz Ahmed 7 | Created : 15 July 2016 8 | Updated : 30 August 2022 9 | Problem : https://www.hackerrank.com/challenges/zipped/problem 10 | """ 11 | 12 | N, X = map(int, input().split()) 13 | scores = [] 14 | for _ in range(X): 15 | scores.append(list(map(float, input().split()))) 16 | for i in zip(*scores): 17 | print(sum(i) / len(i)) 18 | -------------------------------------------------------------------------------- /BuiltIns/ginortS.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : ginortS 3 | Subdomain : Built-Ins 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Updater : Imtiaz Ahmed 7 | Created : 15 July 2016 8 | Updated : 29 August 2022 9 | Problem : https://www.hackerrank.com/challenges/ginorts/problem 10 | """ 11 | 12 | s = input() 13 | print( 14 | "".join( 15 | sorted( 16 | s, 17 | key=lambda x: ( 18 | x.isdigit() and int(x) % 2 == 0, 19 | x.isdigit(), 20 | x.isupper(), 21 | x.islower(), 22 | x, 23 | ), 24 | ) 25 | ) 26 | ) 27 | -------------------------------------------------------------------------------- /Classes/Class2FindtheTorsionalAngle.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | """ 4 | Title : Class 2 - Find the Torsional Angle 5 | Subdomain : Classes 6 | Domain : Python 7 | Author : Ahmedur Rahman Shovon 8 | Updater : Imtiaz Ahmed 9 | Created : 15 July 2016 10 | Updated : 30 August 2022 11 | Problem : https://www.hackerrank.com/challenges/class-2-find-the-torsional-angle/problem 12 | """ 13 | 14 | 15 | class Points: 16 | def __init__(self, x, y, z): 17 | self.x = x 18 | self.y = y 19 | self.z = z 20 | 21 | def __sub__(self, other): 22 | return Points(self.x - other.x, self.y - other.y, self.z - other.z) 23 | 24 | def dot(self, other): 25 | return self.x * other.x + self.y * other.y + self.z * other.z 26 | 27 | def absolute(self): 28 | return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) 29 | 30 | def cross(self, other): 31 | return Points( 32 | self.y * other.z - self.z * other.y, 33 | self.z * other.x - self.x * other.z, 34 | self.x * other.y - self.y * other.x, 35 | ) 36 | 37 | 38 | if __name__ == "__main__": 39 | points = list() 40 | for i in range(4): 41 | a = list(map(float, input().split())) 42 | points.append(a) 43 | 44 | a, b, c, d = ( 45 | Points(*points[0]), 46 | Points(*points[1]), 47 | Points(*points[2]), 48 | Points(*points[3]), 49 | ) 50 | x = (b - a).cross(c - b) 51 | y = (c - b).cross(d - c) 52 | angle = math.acos(x.dot(y) / (x.absolute() * y.absolute())) 53 | 54 | print("%.2f" % math.degrees(angle)) 55 | -------------------------------------------------------------------------------- /Classes/ClassesDealingwithComplexNumbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Classes: Dealing with Complex Numbers 3 | Subdomain : Classes 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Updater : Imtiaz Ahmed 7 | Created : 15 July 2016 8 | Updated : 30 August 2022 9 | Problem : https://www.hackerrank.com/challenges/class-1-dealing-with-complex-numbers/problem 10 | """ 11 | 12 | import math 13 | 14 | 15 | class Complex: 16 | def __init__(self, real, imaginary): 17 | self.real = real 18 | self.imaginary = imaginary 19 | 20 | def __add__(self, no): 21 | return Complex(self.real + no.real, self.imaginary + no.imaginary) 22 | 23 | def __sub__(self, no): 24 | return Complex(self.real - no.real, self.imaginary - no.imaginary) 25 | 26 | def __mul__(self, no): 27 | return Complex( 28 | self.real * no.real - self.imaginary * no.imaginary, 29 | self.real * no.imaginary + self.imaginary * no.real, 30 | ) 31 | 32 | def __truediv__(self, no): 33 | divider = no.real**2 + no.imaginary**2 34 | return Complex( 35 | (self.real * no.real + self.imaginary * no.imaginary) / divider, 36 | (self.imaginary * no.real - self.real * no.imaginary) / divider, 37 | ) 38 | 39 | def mod(self): 40 | return Complex(math.sqrt(self.real**2 + self.imaginary**2), 0.00) 41 | 42 | def __str__(self): 43 | if self.imaginary == 0: 44 | result = "%.2f+0.00i" % (self.real) 45 | elif self.real == 0: 46 | if self.imaginary >= 0: 47 | result = "0.00+%.2fi" % (self.imaginary) 48 | else: 49 | result = "0.00-%.2fi" % (abs(self.imaginary)) 50 | elif self.imaginary > 0: 51 | result = "%.2f+%.2fi" % (self.real, self.imaginary) 52 | else: 53 | result = "%.2f-%.2fi" % (self.real, abs(self.imaginary)) 54 | return result 55 | 56 | 57 | if __name__ == "__main__": 58 | c = map(float, input().split()) 59 | d = map(float, input().split()) 60 | x = Complex(*c) 61 | y = Complex(*d) 62 | print(*map(str, [x + y, x - y, x * y, x / y, x.mod(), y.mod()]), sep="\n") 63 | -------------------------------------------------------------------------------- /ClosuresandDecorators/Decorators2NameDirectory.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Decorators 2 - Name Directory 3 | Subdomain : Closures and Decorators 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 3 April 2021 8 | Problem : https://www.hackerrank.com/challenges/decorators-2-name-directory/problem 9 | """ 10 | 11 | import operator 12 | 13 | 14 | def person_lister(func): 15 | def inner(people): 16 | return [func(p) for p in sorted(people, key=lambda x: (int(x[2])))] 17 | 18 | return inner 19 | 20 | 21 | @person_lister 22 | def name_format(person): 23 | return ("Mr. " if person[3] == "M" else "Ms. ") + person[0] + " " + person[1] 24 | 25 | 26 | if __name__ == "__main__": 27 | people = [input().split() for i in range(int(input()))] 28 | print(*name_format(people), sep="\n") 29 | -------------------------------------------------------------------------------- /ClosuresandDecorators/StandardizeMobileNumberUsingDecorators.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Standardize Mobile Number Using Decorators 3 | Subdomain : Closures and Decorators 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/standardize-mobile-number-using-decorators/problem 8 | """ 9 | 10 | # Enter your code here. Read input from STDIN. Print output to STDOUT 11 | n = int(input()) 12 | ar = [] 13 | for _ in range(n): 14 | tmp_str = input() 15 | tmp_str = tmp_str[len(tmp_str) - 10 :] 16 | ar.append(tmp_str) 17 | 18 | ar.sort() 19 | for item in ar: 20 | print(f"+91 {item[:5]} {item[5:]}") 21 | -------------------------------------------------------------------------------- /Collections/CollectionsOrderedDict.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Collections.OrderedDict() 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 26 November 2024 8 | Problem : https://www.hackerrank.com/challenges/py-collections-ordereddict/problem 9 | """ 10 | 11 | from collections import OrderedDict 12 | 13 | 14 | if __name__ == "__main__": 15 | ordered_dictionary = OrderedDict() 16 | 17 | n = int(input()) 18 | 19 | for _ in range(n): 20 | s = list(input().split()) 21 | price = int(s[len(s) - 1]) 22 | name = " ".join(s[: len(s) - 1]) 23 | 24 | if ordered_dictionary.get(name): 25 | ordered_dictionary[name] += price 26 | else: 27 | ordered_dictionary[name] = price 28 | 29 | for key, value in ordered_dictionary.items(): 30 | print(key, value) 31 | -------------------------------------------------------------------------------- /Collections/Collectionsdeque.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Collections.deque() 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/py-collections-deque/problem 8 | """ 9 | 10 | import collections 11 | 12 | n = int(input()) 13 | d = collections.deque() 14 | for _ in range(n): 15 | cmd = list(input().strip().split()) 16 | opt = cmd[0] 17 | if opt == "append": 18 | d.append(int(cmd[1])) 19 | elif opt == "appendleft": 20 | d.appendleft(int(cmd[1])) 21 | elif opt == "pop": 22 | d.pop() 23 | elif opt == "popleft": 24 | d.popleft() 25 | for i in d: 26 | print(i, end=" ") 27 | -------------------------------------------------------------------------------- /Collections/Collectionsnamedtuple.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Collections.namedtuple() 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 09 February 2023 8 | Problem : https://www.hackerrank.com/challenges/py-collections-namedtuple/problem 9 | """ 10 | 11 | from collections import namedtuple 12 | 13 | n = int(input()) 14 | columns = ",".join(input().split()) 15 | Student = namedtuple("Student", columns) 16 | data = [] 17 | for i in range(n): 18 | row = input().split() 19 | s = Student._make(row) 20 | data.append(s) 21 | avg = sum(float(s.MARKS) for s in data) / n 22 | print(f"{avg:.2f}") 23 | -------------------------------------------------------------------------------- /Collections/DefaultDictTutorial.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : DefaultDict Tutorial 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/defaultdict-tutorial/problem 8 | """ 9 | 10 | from collections import defaultdict 11 | 12 | d = defaultdict(list) 13 | n, m = map(int, input().split()) 14 | for i in range(n): 15 | w = input() 16 | d[w].append(str(i + 1)) 17 | for _ in range(m): 18 | w = input() 19 | print(" ".join(d[w]) or -1) 20 | -------------------------------------------------------------------------------- /Collections/MostCommon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Most Common 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/most-commons/problem 8 | """ 9 | 10 | import collections 11 | 12 | s = sorted(input().strip()) 13 | s_counter = collections.Counter(s).most_common() 14 | """ 15 | s_counter_length = len(s_counter) 16 | for i in range(0,s_counter_length,1): 17 | for j in range(i+1,s_counter_length,1): 18 | if (s_counter[i][1] == s_counter[j][1]) and (ord(s_counter[j][0]) < ord(s_counter[i][0])): 19 | s_counter[i],s_counter[j] = s_counter[j],s_counter[i] 20 | """ 21 | s_counter = sorted(s_counter, key=lambda x: (x[1] * -1, x[0])) 22 | for i in range(3): 23 | print(s_counter[i][0], s_counter[i][1]) 24 | -------------------------------------------------------------------------------- /Collections/PilingUp.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Piling Up! 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/piling-up/problem 8 | """ 9 | 10 | from collections import deque 11 | 12 | cas = int(input()) 13 | for _ in range(cas): 14 | n = int(input()) 15 | dq = deque(map(int, input().split())) 16 | possible = True 17 | element = (2**31) + 1 18 | while dq: 19 | left_element = dq[0] 20 | right_element = dq[-1] 21 | if left_element >= right_element and element >= left_element: 22 | element = dq.popleft() 23 | elif right_element >= left_element and element >= right_element: 24 | element = dq.pop() 25 | else: 26 | possible = False 27 | break 28 | if possible: 29 | print("Yes") 30 | else: 31 | print("No") 32 | -------------------------------------------------------------------------------- /Collections/WordOrder.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Word Order 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/word-order/problem 8 | """ 9 | 10 | from collections import Counter, OrderedDict 11 | 12 | 13 | class OrderedCounter(Counter, OrderedDict): 14 | pass 15 | 16 | 17 | word_ar = [] 18 | n = int(input()) 19 | for i in range(n): 20 | word_ar.append(input().strip()) 21 | word_counter = OrderedCounter(word_ar) 22 | print(len(word_counter)) 23 | for word in word_counter: 24 | print(word_counter[word], end=" ") 25 | -------------------------------------------------------------------------------- /Collections/collectionsCounter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : collections.Counter() 3 | Subdomain : Collections 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 26 November 2024 8 | Problem : https://www.hackerrank.com/challenges/collections-counter/problem 9 | """ 10 | 11 | import collections 12 | 13 | 14 | if __name__ == "__main__": 15 | total_shoes = int(input()) 16 | shoe_sizes = list(map(int, input().split())) 17 | inventory = collections.Counter(shoe_sizes) 18 | 19 | total_customers = int(input()) 20 | total_revenue = 0 21 | 22 | for _ in range(total_customers): 23 | size, price = map(int, input().split()) 24 | if inventory.get(size) and inventory[size] > 0: 25 | total_revenue += price 26 | inventory[size] -= 1 27 | 28 | print(total_revenue) 29 | -------------------------------------------------------------------------------- /DateandTime/CalendarModule.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Calendar Module 3 | Subdomain : Date and Time 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/calendar-module/problem 8 | """ 9 | 10 | import calendar 11 | import datetime 12 | 13 | m, d, y = map(int, input().split()) 14 | input_date = datetime.date(y, m, d) 15 | print(calendar.day_name[input_date.weekday()].upper()) 16 | -------------------------------------------------------------------------------- /DateandTime/TimeDelta.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Time Delta 3 | Subdomain : Date and Time 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-time-delta/problem 8 | """ 9 | 10 | import datetime 11 | 12 | cas = int(input()) 13 | time_format = "%a %d %b %Y %H:%M:%S %z" 14 | for _ in range(cas): 15 | timestamp1 = input().strip() 16 | timestamp2 = input().strip() 17 | time_second1 = datetime.datetime.strptime(timestamp1, time_format) 18 | time_second2 = datetime.datetime.strptime(timestamp2, time_format) 19 | print(int(abs((time_second1 - time_second2).total_seconds()))) 20 | -------------------------------------------------------------------------------- /Debugging/DefaultArguments.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Default Arguments 3 | Subdomain : Debugging 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 08 July 2018 7 | Problem : https://www.hackerrank.com/challenges/default-arguments/problem 8 | """ 9 | 10 | 11 | def print_from_stream(n, stream=EvenStream()): 12 | stream.__init__() 13 | for _ in range(n): 14 | print(stream.get_next()) 15 | -------------------------------------------------------------------------------- /Debugging/WordsScore.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Words Score 3 | Subdomain : Debugging 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 08 July 2018 7 | Problem : https://www.hackerrank.com/challenges/words-score/problem 8 | """ 9 | 10 | 11 | def is_vowel(letter): 12 | return letter in ["a", "e", "i", "o", "u", "y"] 13 | 14 | 15 | def score_words(words): 16 | score = 0 17 | for word in words: 18 | num_vowels = sum(1 for letter in word if is_vowel(letter)) 19 | score += 2 if num_vowels % 2 == 0 else 1 20 | return score 21 | -------------------------------------------------------------------------------- /ErrorsandExceptions/Exceptions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Exceptions 3 | Subdomain : Errors and Exceptions 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/exceptions/problem 8 | """ 9 | 10 | n = int(input()) 11 | for _ in range(n): 12 | a, b = input().split() 13 | try: 14 | print(int(a) // int(b)) 15 | except Exception as e: 16 | print(f"Error Code: {e}") 17 | -------------------------------------------------------------------------------- /ErrorsandExceptions/IncorrectRegex.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Incorrect Regex 3 | Subdomain : Errors and Exceptions 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/incorrect-regex/problem 8 | """ 9 | 10 | import re 11 | 12 | n = int(input()) 13 | for _ in range(n): 14 | s = input() 15 | try: 16 | re.compile(s) 17 | print(True) 18 | except Exception as e: 19 | print(False) 20 | -------------------------------------------------------------------------------- /HackerrankUtility/Hackerrank_Solution_Blank_File_Creator.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Hackerrank_Solution_Blank_File_Creator 3 | Subdomain : None 4 | Domain : None 5 | Author : Ahmedur Rahman Shovon 6 | Created : 12 July 2017 7 | """ 8 | 9 | import datetime 10 | import os 11 | import re 12 | import sys 13 | 14 | extension = ".py" 15 | domain = "Python" 16 | author = "Ahmedur Rahman Shovon" 17 | created_date = datetime.datetime.today().strftime("%d %B %Y") 18 | info_file_name = "python_info.txt" 19 | 20 | 21 | def valid_name(given_name): 22 | return re.sub(r"[^\w]", "", given_name) 23 | 24 | 25 | def write_file_header(title, subdomain): 26 | header_str = "'''\n" 27 | header_str += "Title : " + title + "\n" 28 | header_str += "Subdomain : " + subdomain + "\n" 29 | header_str += "Domain : " + domain + "\n" 30 | header_str += "Author : " + author + "\n" 31 | header_str += "Created : " + created_date + "\n" 32 | header_str += "'''\n" 33 | return header_str 34 | 35 | 36 | problem_list = "" 37 | subdomain_name = "" 38 | 39 | info_file = open(info_file_name, "r") 40 | info_file_lines = info_file.readlines() 41 | info_file.close() 42 | for line in info_file_lines: 43 | line = line.strip() 44 | if line == "": 45 | continue 46 | elif line[0] == "[": 47 | problem_list = line 48 | else: 49 | subdomain_name = line 50 | if subdomain_name != "" and problem_list != "": 51 | folder_name = valid_name(subdomain_name) 52 | if not os.path.exists(folder_name): 53 | os.makedirs(folder_name) 54 | title_ar = re.findall(r'("[^"]*")', problem_list) 55 | title_ar_len = len(title_ar) 56 | 57 | for title in title_ar: 58 | file_header_str = write_file_header(title[1:-1], subdomain_name) 59 | title_valid = valid_name(title) 60 | f = open(folder_name + "\\" + title_valid + extension, "w") 61 | f.write(file_header_str) 62 | f.close() 63 | 64 | print("Folder: " + str(folder_name) + ". Total files: " + str(title_ar_len)) 65 | subdomain_name = "" 66 | problem_list = "" 67 | -------------------------------------------------------------------------------- /HackerrankUtility/Hackerrank_Solution_Lister.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Hackerrank Solution Lister 3 | Subdomain : None 4 | Domain : None 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2017 7 | """ 8 | 9 | import os 10 | import re 11 | import sys 12 | 13 | info_file_name = "python_info.txt" 14 | 15 | 16 | def get_valid_name(given_name): 17 | return re.sub(r"[^\w]", "", given_name) 18 | 19 | 20 | problem_list = "" 21 | subdomain_name = "" 22 | extension = ".py" 23 | 24 | info_file = open(info_file_name, "r") 25 | info_file_lines = info_file.readlines() 26 | info_file.close() 27 | output_file_name = "solution_list.html" 28 | f = open(output_file_name, "w") 29 | f.write("\n") 30 | for line in info_file_lines: 31 | line = line.strip() 32 | if line == "": 33 | continue 34 | elif line[0] == "[": 35 | problem_list = line 36 | else: 37 | subdomain_name = line 38 | if subdomain_name != "" and problem_list != "": 39 | folder_name = get_valid_name(subdomain_name) 40 | title_ar = re.findall(r'("[^"]*")', problem_list) 41 | title_ar_len = len(title_ar) 42 | f.write("- " + subdomain_name + "\n") 43 | for title in title_ar: 44 | filename = get_valid_name(title[1:-1]) 45 | filepath = folder_name + "/" + filename + extension 46 | f.write(" - [" + title[1:-1] + "](" + filepath + ")\n") 47 | subdomain_name = "" 48 | problem_list = "" 49 | f.close() 50 | print("List generated successfully. Open " + output_file_name + " to view.") 51 | -------------------------------------------------------------------------------- /HackerrankUtility/js_code.txt: -------------------------------------------------------------------------------- 1 | $ar = [] 2 | $('.challengecard-title>.js-track-click').each(function(){ 3 | $title = $(this).html().trim(); 4 | $title = $title.toString().replace(/"/g,''); 5 | $title = $title.replace(/'/g,''); 6 | $ar.push($title); 7 | }) 8 | $subdomain = $('.current>a').html().trim(); 9 | console.log($subdomain); 10 | console.log($ar); 11 | -------------------------------------------------------------------------------- /HackerrankUtility/python_info.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ["Say Hello, World! With Python", "Reading Raw Input", "Python If-Else", "Arithmetic Operators", "Python: Division", "Loops", "Write a function", "Print Function"] 3 | 4 | Basic Data Types 5 | ["Lists", "Tuples", "List Comprehensions", "Find the Second Largest Number", "Nested Lists", "Finding the percentage"] 6 | 7 | Strings 8 | ["sWAP cASE", "String Split and Join", "Whats Your Name?", "Mutations", "Find a string", "String Validators", "Text Alignment", "Text Wrap", "Designer Door Mat", "String Formatting", "Alphabet Rangoli", "Capitalize!", "The Minion Game"] 9 | 10 | Sets 11 | ["Introduction to Sets", "Symmetric Difference", "No Idea!", "Set .add()", "Set .discard(), .remove() & .pop()", "Set .union() Operation", "Set .intersection() Operation", "Set .difference() Operation", "Set .symmetric_difference() Operation", "Set Mutations", "The Captains Room", "Check Subset", "Check Strict Superset"] 12 | 13 | Math 14 | ["Polar Coordinates", "Find Angle MBC", "Triangle Quest 2", "Mod Divmod", "Power - Mod Power", "Integers Come In All Sizes", "Triangle Quest"] 15 | 16 | Itertools 17 | ["itertools.product()", "itertools.permutations()", "itertools.combinations()", "itertools.combinations_with_replacement()", "Compress the String!", "Iterables and Iterators", "Maximize It!"] 18 | 19 | Collections 20 | ["collections.Counter()", "DefaultDict Tutorial", "Collections.namedtuple()", "Collections.OrderedDict()", "Word Order", "Collections.deque()", "Piling Up!", "Most Common"] 21 | 22 | Date and Time 23 | ["Calendar Module", "Time Delta"] 24 | 25 | Errors and Exceptions 26 | ["Exceptions", "Incorrect Regex"] 27 | 28 | Classes 29 | ["Classes: Dealing with Complex Numbers", "Class 2 - Find the Torsional Angle"] 30 | 31 | Built-Ins 32 | ["Zipped!", "Input()", "Python Evaluation", "Sort Data", "Any or All", "ginortS"] 33 | 34 | Python Functionals 35 | ["Map and Lambda Function", "Validating Email Addresses With a Filter"] 36 | 37 | Regex and Parsing 38 | ["Introduction to Regex Module", "Re.split()", "Group(), Groups() & Groupdict()", "Re.findall() & Re.finditer()", "Re.start() & Re.end()", "Regex Substitution", "Validating Roman Numerals", "Validating phone numbers", "Validating and Parsing Email Addresses", "Hex Color Code", "HTML Parser - Part 1", "HTML Parser - Part 2", "Detect HTML Tags, Attributes and Attribute Values", "Validating UID", "Validating Credit Card Numbers", "Validating Postal Codes", "Matrix Script"] 39 | 40 | XML 41 | ["XML 1 - Find the Score", "XML2 - Find the Maximum Depth"] 42 | 43 | Closures and Decorators 44 | ["Standardize Mobile Number Using Decorators", "Decorators 2 - Name Directory"] 45 | 46 | Numpy 47 | ["Arrays", "Shape and Reshape", "Transpose and Flatten", "Concatenate", "Zeros and Ones", "Eye and Identity", "Array Mathematics", "Floor, Ceil and Rint", "Sum and Prod", "Min and Max", "Mean, Var, and Std", "Dot and Cross", "Inner and Outer", "Polynomials", "Linear Algebra"] 48 | 49 | Debugging 50 | ["Words Score", "Default Arguments"] 51 | 52 | -------------------------------------------------------------------------------- /HackerrankUtility/solution_list.html: -------------------------------------------------------------------------------- 1 | 2 | - Introduction 3 | - [Say Hello, World! With Python](Introduction/SayHelloWorldWithPython.py) 4 | - [Reading Raw Input](Introduction/ReadingRawInput.py) 5 | - [Python If-Else](Introduction/PythonIfElse.py) 6 | - [Arithmetic Operators](Introduction/ArithmeticOperators.py) 7 | - [Python: Division](Introduction/PythonDivision.py) 8 | - [Loops](Introduction/Loops.py) 9 | - [Write a function](Introduction/Writeafunction.py) 10 | - [Print Function](Introduction/PrintFunction.py) 11 | - Basic Data Types 12 | - [Lists](BasicDataTypes/Lists.py) 13 | - [Tuples](BasicDataTypes/Tuples.py) 14 | - [List Comprehensions](BasicDataTypes/ListComprehensions.py) 15 | - [Find the Second Largest Number](BasicDataTypes/FindtheSecondLargestNumber.py) 16 | - [Nested Lists](BasicDataTypes/NestedLists.py) 17 | - [Finding the percentage](BasicDataTypes/Findingthepercentage.py) 18 | - Strings 19 | - [sWAP cASE](Strings/sWAPcASE.py) 20 | - [String Split and Join](Strings/StringSplitandJoin.py) 21 | - [Whats Your Name?](Strings/WhatsYourName.py) 22 | - [Mutations](Strings/Mutations.py) 23 | - [Find a string](Strings/Findastring.py) 24 | - [String Validators](Strings/StringValidators.py) 25 | - [Text Alignment](Strings/TextAlignment.py) 26 | - [Text Wrap](Strings/TextWrap.py) 27 | - [Designer Door Mat](Strings/DesignerDoorMat.py) 28 | - [String Formatting](Strings/StringFormatting.py) 29 | - [Alphabet Rangoli](Strings/AlphabetRangoli.py) 30 | - [Capitalize!](Strings/Capitalize.py) 31 | - [The Minion Game](Strings/TheMinionGame.py) 32 | - Sets 33 | - [Introduction to Sets](Sets/IntroductiontoSets.py) 34 | - [Symmetric Difference](Sets/SymmetricDifference.py) 35 | - [No Idea!](Sets/NoIdea.py) 36 | - [Set .add()](Sets/Setadd.py) 37 | - [Set .discard(), .remove() & .pop()](Sets/Setdiscardremoveamppop.py) 38 | - [Set .union() Operation](Sets/SetunionOperation.py) 39 | - [Set .intersection() Operation](Sets/SetintersectionOperation.py) 40 | - [Set .difference() Operation](Sets/SetdifferenceOperation.py) 41 | - [Set .symmetric_difference() Operation](Sets/Setsymmetric_differenceOperation.py) 42 | - [Set Mutations](Sets/SetMutations.py) 43 | - [The Captains Room](Sets/TheCaptainsRoom.py) 44 | - [Check Subset](Sets/CheckSubset.py) 45 | - [Check Strict Superset](Sets/CheckStrictSuperset.py) 46 | - Math 47 | - [Polar Coordinates](Math/PolarCoordinates.py) 48 | - [Find Angle MBC](Math/FindAngleMBC.py) 49 | - [Triangle Quest 2](Math/TriangleQuest2.py) 50 | - [Mod Divmod](Math/ModDivmod.py) 51 | - [Power - Mod Power](Math/PowerModPower.py) 52 | - [Integers Come In All Sizes](Math/IntegersComeInAllSizes.py) 53 | - [Triangle Quest](Math/TriangleQuest.py) 54 | - Itertools 55 | - [itertools.product()](Itertools/itertoolsproduct.py) 56 | - [itertools.permutations()](Itertools/itertoolspermutations.py) 57 | - [itertools.combinations()](Itertools/itertoolscombinations.py) 58 | - [itertools.combinations_with_replacement()](Itertools/itertoolscombinations_with_replacement.py) 59 | - [Compress the String!](Itertools/CompresstheString.py) 60 | - [Iterables and Iterators](Itertools/IterablesandIterators.py) 61 | - [Maximize It!](Itertools/MaximizeIt.py) 62 | - Collections 63 | - [collections.Counter()](Collections/collectionsCounter.py) 64 | - [DefaultDict Tutorial](Collections/DefaultDictTutorial.py) 65 | - [Collections.namedtuple()](Collections/Collectionsnamedtuple.py) 66 | - [Collections.OrderedDict()](Collections/CollectionsOrderedDict.py) 67 | - [Word Order](Collections/WordOrder.py) 68 | - [Collections.deque()](Collections/Collectionsdeque.py) 69 | - [Piling Up!](Collections/PilingUp.py) 70 | - [Most Common](Collections/MostCommon.py) 71 | - Date and Time 72 | - [Calendar Module](DateandTime/CalendarModule.py) 73 | - [Time Delta](DateandTime/TimeDelta.py) 74 | - Errors and Exceptions 75 | - [Exceptions](ErrorsandExceptions/Exceptions.py) 76 | - [Incorrect Regex](ErrorsandExceptions/IncorrectRegex.py) 77 | - Classes 78 | - [Classes: Dealing with Complex Numbers](Classes/ClassesDealingwithComplexNumbers.py) 79 | - [Class 2 - Find the Torsional Angle](Classes/Class2FindtheTorsionalAngle.py) 80 | - Built-Ins 81 | - [Zipped!](BuiltIns/Zipped.py) 82 | - [Input()](BuiltIns/Input.py) 83 | - [Python Evaluation](BuiltIns/PythonEvaluation.py) 84 | - [Sort Data](BuiltIns/SortData.py) 85 | - [Any or All](BuiltIns/AnyorAll.py) 86 | - [ginortS](BuiltIns/ginortS.py) 87 | - Python Functionals 88 | - [Map and Lambda Function](PythonFunctionals/MapandLambdaFunction.py) 89 | - [Validating Email Addresses With a Filter](PythonFunctionals/ValidatingEmailAddressesWithaFilter.py) 90 | - Regex and Parsing 91 | - [Introduction to Regex Module](RegexandParsing/IntroductiontoRegexModule.py) 92 | - [Re.split()](RegexandParsing/Resplit.py) 93 | - [Group(), Groups() & Groupdict()](RegexandParsing/GroupGroupsampGroupdict.py) 94 | - [Re.findall() & Re.finditer()](RegexandParsing/RefindallampRefinditer.py) 95 | - [Re.start() & Re.end()](RegexandParsing/RestartampReend.py) 96 | - [Regex Substitution](RegexandParsing/RegexSubstitution.py) 97 | - [Validating Roman Numerals](RegexandParsing/ValidatingRomanNumerals.py) 98 | - [Validating phone numbers](RegexandParsing/Validatingphonenumbers.py) 99 | - [Validating and Parsing Email Addresses](RegexandParsing/ValidatingandParsingEmailAddresses.py) 100 | - [Hex Color Code](RegexandParsing/HexColorCode.py) 101 | - [HTML Parser - Part 1](RegexandParsing/HTMLParserPart1.py) 102 | - [HTML Parser - Part 2](RegexandParsing/HTMLParserPart2.py) 103 | - [Detect HTML Tags, Attributes and Attribute Values](RegexandParsing/DetectHTMLTagsAttributesandAttributeValues.py) 104 | - [Validating UID](RegexandParsing/ValidatingUID.py) 105 | - [Validating Credit Card Numbers](RegexandParsing/ValidatingCreditCardNumbers.py) 106 | - [Validating Postal Codes](RegexandParsing/ValidatingPostalCodes.py) 107 | - [Matrix Script](RegexandParsing/MatrixScript.py) 108 | - XML 109 | - [XML 1 - Find the Score](XML/XML1FindtheScore.py) 110 | - [XML2 - Find the Maximum Depth](XML/XML2FindtheMaximumDepth.py) 111 | - Closures and Decorators 112 | - [Standardize Mobile Number Using Decorators](ClosuresandDecorators/StandardizeMobileNumberUsingDecorators.py) 113 | - [Decorators 2 - Name Directory](ClosuresandDecorators/Decorators2NameDirectory.py) 114 | - Numpy 115 | - [Arrays](Numpy/Arrays.py) 116 | - [Shape and Reshape](Numpy/ShapeandReshape.py) 117 | - [Transpose and Flatten](Numpy/TransposeandFlatten.py) 118 | - [Concatenate](Numpy/Concatenate.py) 119 | - [Zeros and Ones](Numpy/ZerosandOnes.py) 120 | - [Eye and Identity](Numpy/EyeandIdentity.py) 121 | - [Array Mathematics](Numpy/ArrayMathematics.py) 122 | - [Floor, Ceil and Rint](Numpy/FloorCeilandRint.py) 123 | - [Sum and Prod](Numpy/SumandProd.py) 124 | - [Min and Max](Numpy/MinandMax.py) 125 | - [Mean, Var, and Std](Numpy/MeanVarandStd.py) 126 | - [Dot and Cross](Numpy/DotandCross.py) 127 | - [Inner and Outer](Numpy/InnerandOuter.py) 128 | - [Polynomials](Numpy/Polynomials.py) 129 | - [Linear Algebra](Numpy/LinearAlgebra.py) 130 | - Debugging 131 | - [Words Score](Debugging/WordsScore.py) 132 | - [Default Arguments](Debugging/DefaultArguments.py) 133 | -------------------------------------------------------------------------------- /Hackerrank_Python_Domain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arsho/Hackerrank_Python_Domain_Solutions/502e8e2e00f5d1610be1ed03064366dfd15290e4/Hackerrank_Python_Domain.png -------------------------------------------------------------------------------- /Hackerrank_Python_Domain_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arsho/Hackerrank_Python_Domain_Solutions/502e8e2e00f5d1610be1ed03064366dfd15290e4/Hackerrank_Python_Domain_old.png -------------------------------------------------------------------------------- /Introduction/ArithmeticOperators.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Arithmetic Operators 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 April 2020 7 | Problem : https://www.hackerrank.com/challenges/python-arithmetic-operators/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | a = int(input()) 12 | b = int(input()) 13 | print(a + b) 14 | print(a - b) 15 | print(a * b) 16 | -------------------------------------------------------------------------------- /Introduction/Loops.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Loops 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 13 May 2020 7 | Problem : https://www.hackerrank.com/challenges/python-loops/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | n = int(input()) 12 | for i in range(n): 13 | print(i * i) 14 | -------------------------------------------------------------------------------- /Introduction/PrintFunction.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Print Function 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/python-print/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | n = int(input()) 12 | ar = range(1, n + 1) 13 | for i in ar: 14 | print(i, end="") 15 | 16 | """ 17 | Alternate solution: 18 | 19 | if __name__ == '__main__': 20 | n = int(input()) 21 | print("".join([str(i) for i in range(1,n+1)])) 22 | 23 | """ 24 | -------------------------------------------------------------------------------- /Introduction/PythonDivision.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Python: Division 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/python-division/problem 8 | """ 9 | 10 | if __name__ == "__main__": 11 | a = int(input()) 12 | b = int(input()) 13 | print(a // b) 14 | print(a / b) 15 | -------------------------------------------------------------------------------- /Introduction/PythonIfElse.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Python If-Else 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Utkarsh Mishra 6 | Created : 27 Jan 2021 7 | Problem : https://www.hackerrank.com/challenges/py-if-else/problem 8 | """ 9 | 10 | import sys 11 | 12 | n = int(input()) 13 | if n % 2 == 1 or n in range(5, 21): 14 | print("Weird") 15 | else: 16 | print("Not Weird") 17 | -------------------------------------------------------------------------------- /Introduction/SayHelloWorldWithPython.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Say Hello, World! With Python 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 23 July 2018 7 | Problem : https://www.hackerrank.com/challenges/py-hello-world/problem 8 | """ 9 | 10 | print("Hello, World!") 11 | -------------------------------------------------------------------------------- /Introduction/Writeafunction.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Write a function 3 | Subdomain : Introduction 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 06 July 2020 7 | Problem : https://www.hackerrank.com/challenges/write-a-function/problem 8 | """ 9 | 10 | 11 | def is_leap(year): 12 | leap = False 13 | leap = (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0) 14 | return leap 15 | 16 | 17 | year = int(input()) 18 | print(is_leap(year)) 19 | -------------------------------------------------------------------------------- /Itertools/CompresstheString.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Compress the String! 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/compress-the-string/problem 8 | """ 9 | 10 | import itertools 11 | 12 | s = input().strip() 13 | s_unique_element = list(set(s)) 14 | group = [] 15 | key = [] 16 | for k, g in itertools.groupby(s): 17 | group.append(list(g)) 18 | key.append(k) 19 | for i in range(len(group)): 20 | group_length = len(group[i]) 21 | k = int(key[i]) 22 | print((group_length, k), end=" ") 23 | -------------------------------------------------------------------------------- /Itertools/IterablesandIterators.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Iterables and Iterators 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/iterables-and-iterators/problem 8 | """ 9 | 10 | from itertools import combinations 11 | 12 | n = int(input()) 13 | ar = input().split() 14 | k = int(input()) 15 | comb_list = list(combinations(ar, k)) 16 | a_list = [e for e in comb_list if "a" in e] 17 | print(len(a_list) / len(comb_list)) 18 | -------------------------------------------------------------------------------- /Itertools/MaximizeIt.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Maximize It! 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/maximize-it/problem 8 | """ 9 | 10 | import itertools 11 | 12 | k, m = map(int, input().split()) 13 | 14 | main_ar = [] 15 | for _ in range(k): 16 | ar = list(map(int, input().split())) 17 | main_ar.append(ar[1:]) 18 | 19 | all_combination = itertools.product(*main_ar) 20 | result = 0 21 | for single_combination in all_combination: 22 | result = max(sum(x * x for x in single_combination) % m, result) 23 | print(result) 24 | -------------------------------------------------------------------------------- /Itertools/itertoolscombinations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : itertools.combinations() 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/itertools-combinations/problem 8 | """ 9 | 10 | from itertools import * 11 | 12 | s, n = input().split() 13 | n = int(n) + 1 14 | s = sorted(s) 15 | for i in range(1, n): 16 | for j in combinations(s, i): 17 | print("".join(j)) 18 | -------------------------------------------------------------------------------- /Itertools/itertoolscombinations_with_replacement.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : itertools.combinations_with_replacement() 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/itertools-combinations-with-replacement/problem 8 | """ 9 | 10 | from itertools import * 11 | 12 | s, n = input().split() 13 | n = int(n) 14 | s = sorted(s) 15 | for j in combinations_with_replacement(s, n): 16 | print("".join(j)) 17 | -------------------------------------------------------------------------------- /Itertools/itertoolspermutations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : itertools.permutations() 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/itertools-permutations/problem 8 | """ 9 | 10 | import itertools 11 | 12 | s, n = list(map(str, input().split(" "))) 13 | s = sorted(s) 14 | for p in list(itertools.permutations(s, int(n))): 15 | print("".join(p)) 16 | -------------------------------------------------------------------------------- /Itertools/itertoolsproduct.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : itertools.product() 3 | Subdomain : Itertools 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/itertools-product/problem 8 | """ 9 | 10 | import itertools 11 | 12 | ar1 = list(map(int, input().split())) 13 | ar2 = list(map(int, input().split())) 14 | cross = list(itertools.product(ar1, ar2)) 15 | for i in cross: 16 | print(i, end=" ") 17 | -------------------------------------------------------------------------------- /Math/FindAngleMBC.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Find Angle MBC 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 08 February 2023 8 | Problem : https://www.hackerrank.com/challenges/find-angle/problem 9 | """ 10 | 11 | import math 12 | 13 | ab = float(input()) 14 | bc = float(input()) 15 | ac = math.sqrt(ab**2 + bc**2) 16 | bm = ac / 2.0 17 | mc = bm 18 | # let, 19 | b = mc 20 | c = bm 21 | a = bc 22 | # where b=c 23 | angel_b_radian = math.acos(a / (2 * b)) 24 | angel_b_degree = int(round((180 * angel_b_radian) / math.pi)) 25 | print(f"{angel_b_degree}°") 26 | -------------------------------------------------------------------------------- /Math/IntegersComeInAllSizes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Integers Come In All Sizes 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes/problem 8 | """ 9 | 10 | # Enter your code here. Read input from STDIN. Print output to STDOUT 11 | a = int(input()) 12 | b = int(input()) 13 | c = int(input()) 14 | d = int(input()) 15 | print(pow(a, b) + pow(c, d)) 16 | -------------------------------------------------------------------------------- /Math/ModDivmod.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Mod Divmod 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-mod-divmod/problem 8 | """ 9 | 10 | # Enter your code here. Read input from STDIN. Print output to STDOUT 11 | a = int(input()) 12 | b = int(input()) 13 | d = divmod(a, b) 14 | print(d[0]) 15 | print(d[1]) 16 | print(d) 17 | -------------------------------------------------------------------------------- /Math/PolarCoordinates.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Polar Coordinates 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/polar-coordinates/problem 8 | """ 9 | 10 | import cmath 11 | 12 | z = complex(input()) 13 | p = cmath.polar(z) 14 | print(p[0]) 15 | print(p[1]) 16 | -------------------------------------------------------------------------------- /Math/PowerModPower.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Power - Mod Power 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-power-mod-power/problem 8 | """ 9 | 10 | # Enter your code here. Read input from STDIN. Print output to STDOUT 11 | a = int(input()) 12 | b = int(input()) 13 | c = int(input()) 14 | print(pow(a, b)) 15 | print(pow(a, b, c)) 16 | -------------------------------------------------------------------------------- /Math/TriangleQuest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Triangle Quest 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/python-quest-1/problem 8 | """ 9 | 10 | for i in range( 11 | 1, input() 12 | ): # More than 2 lines will result in 0 score. Do not leave a blank line also 13 | print(i * ((10**i - 1) // 9)) 14 | -------------------------------------------------------------------------------- /Math/TriangleQuest2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Triangle Quest 2 3 | Subdomain : Math 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/triangle-quest-2/problem 8 | """ 9 | 10 | for i in range( 11 | 1, int(input()) + 1 12 | ): # More than 2 lines will result in 0 score. Do not leave a blank line also 13 | print(((10**i - 1) // 9) ** 2) 14 | -------------------------------------------------------------------------------- /Numpy/ArrayMathematics.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Array Mathematics 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-array-mathematics/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | if __name__ == "__main__": 14 | n, m = map(int, input().split()) 15 | 16 | ar1 = np.array([input().split() for _ in range(n)], int) 17 | ar2 = np.array([input().split() for _ in range(n)], int) 18 | 19 | print(ar1 + ar2) 20 | print(ar1 - ar2) 21 | print(ar1 * ar2) 22 | print(ar1 // ar2) 23 | print(ar1 % ar2) 24 | print(ar1**ar2) 25 | -------------------------------------------------------------------------------- /Numpy/Arrays.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Arrays 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-arrays/problem 9 | """ 10 | 11 | import numpy 12 | 13 | 14 | def arrays(arr): 15 | np_ar = numpy.array(arr, float) 16 | return np_ar[::-1] 17 | 18 | 19 | arr = input().strip().split(" ") 20 | result = arrays(arr) 21 | print(result) 22 | -------------------------------------------------------------------------------- /Numpy/Concatenate.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Concatenate 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-concatenate/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n, m, p = map(int, input().split()) 16 | 17 | arr1 = [] 18 | arr2 = [] 19 | for _ in range(n): 20 | tmp = list(map(int, input().split())) 21 | arr1.append(tmp) 22 | for _ in range(m): 23 | tmp = list(map(int, input().split())) 24 | arr2.append(tmp) 25 | np_arr1 = np.array(arr1) 26 | np_arr2 = np.array(arr2) 27 | print(np.concatenate((np_arr1, np_arr2), axis=0)) 28 | -------------------------------------------------------------------------------- /Numpy/DotandCross.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Dot and Cross 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-dot-and-cross/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | if __name__ == "__main__": 14 | n = int(input()) 15 | 16 | arr1 = np.array([input().split() for _ in range(n)], int) 17 | arr2 = np.array([input().split() for _ in range(n)], int) 18 | 19 | print(np.dot(arr1, arr2)) 20 | -------------------------------------------------------------------------------- /Numpy/EyeandIdentity.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Eye and Identity 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-eye-and-identity/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | np.set_printoptions(legacy="1.13") 16 | n, m = map(int, input().split()) 17 | print(np.eye(n, m, k=0)) 18 | -------------------------------------------------------------------------------- /Numpy/FloorCeilandRint.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Floor, Ceil and Rint 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/floor-ceil-and-rint/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | np.set_printoptions(legacy="1.13") 16 | arr = np.array(input().split(), float) 17 | print(np.floor(arr)) 18 | print(np.ceil(arr)) 19 | print(np.rint(arr)) 20 | 21 | # Alternate solution 22 | # print(*(f(A) for f in [np.floor, np.ceil, np.rint]), sep='\n') 23 | -------------------------------------------------------------------------------- /Numpy/InnerandOuter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Inner and Outer 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-inner-and-outer/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | arr1 = np.array(list(map(int, input().split()))) 16 | arr2 = np.array(list(map(int, input().split()))) 17 | 18 | print(np.inner(arr1, arr2)) 19 | print(np.outer(arr1, arr2)) 20 | -------------------------------------------------------------------------------- /Numpy/LinearAlgebra.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Linear Algebra 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-linear-algebra/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | np.set_printoptions(legacy="1.13") 16 | n = int(input()) 17 | array = np.array([input().split() for _ in range(n)], float) 18 | print(np.linalg.det(array)) 19 | -------------------------------------------------------------------------------- /Numpy/MeanVarandStd.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Mean, Var, and Std 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-mean-var-and-std/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n, m = map(int, input().split()) 16 | arr = np.array([input().split() for _ in range(n)], int) 17 | 18 | print(np.mean(arr, axis=1)) 19 | print(np.var(arr, axis=0)) 20 | print(round(np.std(arr, axis=None), 11)) 21 | -------------------------------------------------------------------------------- /Numpy/MinandMax.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Min and Max 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-min-and-max/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n, m = map(int, input().split()) 16 | arr = np.array([input().split() for _ in range(n)], int) 17 | result = np.max(np.min(arr, axis=1)) 18 | print(result) 19 | -------------------------------------------------------------------------------- /Numpy/Polynomials.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Polynomials 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-polynomials/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | p = np.array(list(map(float, input().split())), float) 16 | x = float(input()) 17 | print(np.polyval(p, x)) 18 | -------------------------------------------------------------------------------- /Numpy/ShapeandReshape.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Shape and Reshape 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-shape-reshape/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | array = list(map(int, input().split())) 16 | np_arr = np.array(array) 17 | print(np.reshape(np_arr, (3, 3))) 18 | -------------------------------------------------------------------------------- /Numpy/SumandProd.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Sum and Prod 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-sum-and-prod/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n, m = map(int, input().split()) 16 | 17 | arr = np.array([input().split() for _ in range(n)], int) 18 | 19 | s = np.sum(arr, axis=0) 20 | print(np.prod(s)) 21 | -------------------------------------------------------------------------------- /Numpy/TransposeandFlatten.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Transpose and Flatten 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-transpose-and-flatten/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n, m = map(int, input().split()) 16 | arr = [] 17 | for _ in range(n): 18 | row = list(map(int, input().split())) 19 | arr.append(row) 20 | 21 | np_arr = np.array(arr) 22 | print(np.transpose(np_arr)) 23 | print(np_arr.flatten()) 24 | -------------------------------------------------------------------------------- /Numpy/ZerosandOnes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Zeros and Ones 3 | Subdomain : Numpy 4 | Domain : Python 5 | Author : Md Samshad Rahman 6 | Created : 15 July 2016 7 | Updated : 25 November 2024 8 | Problem : https://www.hackerrank.com/challenges/np-zeros-and-ones/problem 9 | """ 10 | 11 | import numpy as np 12 | 13 | 14 | if __name__ == "__main__": 15 | n_arr = list(map(int, input().split())) 16 | n = tuple(n_arr) 17 | print(np.zeros(n, dtype=np.int32)) 18 | print(np.ones(n, dtype=np.int32)) 19 | -------------------------------------------------------------------------------- /PythonFunctionals/MapandLambdaFunction.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Map and Lambda Function 3 | Subdomain : Python Functionals 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 08 February 2023 8 | Problem : https://www.hackerrank.com/challenges/map-and-lambda-expression/problem 9 | """ 10 | 11 | cube = lambda x: x * x * x 12 | 13 | 14 | def fibonacci(n): 15 | ar = [0, 1] 16 | if n < 2: 17 | return ar[:n] 18 | for i in range(2, n): 19 | ar.append(ar[i - 1] + ar[i - 2]) 20 | return ar 21 | 22 | 23 | if __name__ == "__main__": 24 | n = int(input()) 25 | print(list(map(cube, fibonacci(n)))) 26 | -------------------------------------------------------------------------------- /PythonFunctionals/ReduceFunction.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Reduce Function 3 | Subdomain : Python Functionals 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 24 January 2017 7 | Problem : https://www.hackerrank.com/challenges/reduce-function/problem 8 | """ 9 | 10 | from fractions import Fraction 11 | from functools import reduce 12 | 13 | 14 | def product(fracs): 15 | t = Fraction(reduce(lambda x, y: x * y, fracs)) 16 | return t.numerator, t.denominator 17 | 18 | 19 | if __name__ == "__main__": 20 | fracs = [] 21 | for _ in range(int(input())): 22 | fracs.append(Fraction(*map(int, input().split()))) 23 | result = product(fracs) 24 | print(*result) 25 | 26 | """ 27 | 3 28 | 1 2 29 | 3 4 30 | 10 6 31 | """ 32 | -------------------------------------------------------------------------------- /PythonFunctionals/ValidatingEmailAddressesWithaFilter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Validating Email Addresses With a Filter 3 | Subdomain : Python Functionals 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Updated : 08 February 2023 8 | Problem : https://www.hackerrank.com/challenges/validate-list-of-email-address-with-filter/problem 9 | """ 10 | 11 | import re 12 | 13 | 14 | def fun(s): 15 | return re.search(r"^[\w-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$", s) 16 | 17 | 18 | def filter_mail(emails): 19 | return list(filter(fun, emails)) 20 | 21 | 22 | if __name__ == "__main__": 23 | n = int(input()) 24 | emails = [] 25 | for _ in range(n): 26 | emails.append(input()) 27 | 28 | filtered_emails = filter_mail(emails) 29 | filtered_emails.sort() 30 | print(filtered_emails) 31 | -------------------------------------------------------------------------------- /RegexandParsing/DetectFloatingPointNumbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Detect Floating Point Numbers 3 | Subdomain : Regex and Parsing 4 | Domain : Python 5 | Author : Atharva Shah 6 | Created : 3 April 2021 7 | Problem : https://www.hackerrank.com/challenges/introduction-to-regex/problem 8 | """ 9 | 10 | from re import compile, match 11 | 12 | pattern = compile("^[-+]?\d*\.\d+$") 13 | for _ in range(int(input())): 14 | print(bool(pattern.match(input()))) 15 | -------------------------------------------------------------------------------- /RegexandParsing/DetectHTMLTagsAttributesandAttributeValues.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Detect HTML Tags, Attributes and Attribute Values 3 | Subdomain : Regex and Parsing 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/detect-html-tags-attributes-and-attribute-values/problem 8 | """ 9 | 10 | from html.parser import HTMLParser 11 | 12 | 13 | class CustomHTMLParser(HTMLParser): 14 | def handle_starttag(self, tag, attrs): 15 | print(tag) 16 | self.handle_attrs(attrs) 17 | 18 | def handle_startendtag(self, tag, attrs): 19 | print(tag) 20 | self.handle_attrs(attrs) 21 | 22 | def handle_attrs(self, attrs): 23 | for attrs_pair in attrs: 24 | print("->", attrs_pair[0].strip(), ">", attrs_pair[1].strip()) 25 | 26 | 27 | n = int(input()) 28 | html_string = "".join(input() for _ in range(n)) 29 | customHTMLParser = CustomHTMLParser() 30 | customHTMLParser.feed(html_string) 31 | customHTMLParser.close() 32 | -------------------------------------------------------------------------------- /RegexandParsing/GroupGroupsampGroupdict.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : Group(), Groups() & Groupdict() 3 | Subdomain : Regex and Parsing 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/re-group-groups/problem 8 | """ 9 | 10 | import re 11 | 12 | s = input() 13 | res = re.search(r"([A-Za-z0-9])\1", s) 14 | if res is None: 15 | print(-1) 16 | else: 17 | print(res[1]) 18 | -------------------------------------------------------------------------------- /RegexandParsing/HTMLParserPart1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Title : HTML Parser - Part 1 3 | Subdomain : Regex and Parsing 4 | Domain : Python 5 | Author : Ahmedur Rahman Shovon 6 | Created : 15 July 2016 7 | Problem : https://www.hackerrank.com/challenges/html-parser-part-1/problem 8 | """ 9 | 10 | from html.parser import HTMLParser 11 | 12 | 13 | class CustomHTMLParser(HTMLParser): 14 | def handle_attr(self, attrs): 15 | for attr_val_tuple in attrs: 16 | print("->", attr_val_tuple[0], ">", attr_val_tuple[1]) 17 | 18 | def handle_starttag(self, tag, attrs): 19 | print("Start :", tag) 20 | self.handle_attr(attrs) 21 | 22 | def handle_endtag(self, tag): 23 | print("End :", tag) 24 | 25 | def handle_startendtag(self, tag, attrs): 26 | print("Empty :", tag) 27 | self.handle_attr(attrs) 28 | 29 | 30 | parser = CustomHTMLParser() 31 | 32 | n = int(input()) 33 | 34 | s = "".join(input() for _ in range(n)) 35 | parser.feed(s) 36 | 37 | """ 38 | 2 39 |