Skip to main content

Posts

Showing posts from June, 2021

Day 10: Binary Numbers | HackerRank | solution in python

Objective Today, we're working with binary numbers. Task Given a base-  integer,  , convert it to binary (base- ). Then find and print the base-  integer denoting the maximum number of consecutive  's in  's binary representation. When working with different bases, it is common to show the base as a subscript. Example The binary representation of  ...

Day 9: Recursion 3 | HackerRank | solution in python

Objective  Today, we are learning about an algorithmic concept called  recursion . Function Description Complete the  factorial  function in the editor below. Be sure to use recursion. factorial  has the following paramter: int n:  an integer Returns int:  the factorial of  Note:  If you fail to use recursion or fail to name your recursive function  factorial  or  Factorial ,  you will get a score of  . Input Format A single integer,   (the argument to pass to  factorial ). Constraints Your submission must contain a recursive function named  factorial . Sample Input 3 Sample Output 6 #PROGRAM IN PYTHON import math import os import random import re import sys # Complete the factorial function below. def factorial(n): if n==0 or n==1: return 1 else: return n*factorial(n-1) if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') n = int(input()) ...

Day 8: Dictionaries and Maps | HackerRank | solution in python

Program Problem  Objective Today, we're learning about Key-Value pair mappings using a  Map  or  Dictionary  data structure. Task Given   names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each   queried, print the associated entry from your phone book on a new line in the form  name=phoneNumber ; if an entry for   is not found, print  Not found  instead. Note:  Your phone book should be a Dictionary/Map/HashMap data structure. Input Format The first line contains an integer,  , denoting the number of entries in the phone book. Each of the   subsequent lines describes an entry in the form of   space-separated values on a single line. The first value is a friend's name, and the second value is an  -digit phone number. After the   lines o...