Showing posts with label HackerRank solutions. Show all posts
Showing posts with label HackerRank solutions. Show all posts

Friday, February 7, 2020

Day of the Programmer : Algorithms - Implementation

#The solution in Python3 is as follows:


def solve(year):
    if (year == 1918):
        return '26.09.1918'
    elif ((year <= 1917) & (year%4 == 0)) or ((year > 1918) & (year%400 == 0 or ((year%4 == 0) & (year%100 != 0)))):
        return '12.09.%s' %year
    else:
        return '13.09.%s' %year
y=int(input())
print(solve(y))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Saturday, September 1, 2018

Birthday Chocolate : Algorithms - Implementation

#The solution in Python3 is as follows:


def solve(n, a, d, m):
    count = 0
    for i in range(0,n):
          total = sum(a[i:m+i])
          if total == d:
                count+=1
         return count
n=int(input())
a=list(map(int,input().split()))
d,m=map(int,input().split())
print(solve(n,a,d,m))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Monday, August 13, 2018

Sock Merchant : Algorithms - Implementation

#The solution in Python3 is as follows:


n=int(input())
a=list(map(int,input().split()))
b=set(a)
c=0
for i in b:
    if a.count(i)//2>=1:
        c+=(a.count(i)//2)
print(c)

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Monday, August 6, 2018

Bon Appétit : Algorithms - Implementation

#The solution in Python3 is as follows:


n,k=map(int,input().split())
a=list(map(int,input().split()))
b=int(input())
bac=(sum(a)-a[k])//2
if bac==b:
       print("Bon Appetit")
elif bac<b:
       print(b-bac)

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Drawing Book : Algorithms - Implementation

#The solution in Python3 is as follows:


n=int(input())
p=int(input())
if (n%2!=0 and p%2!=0) or (n%2!=0 and p%2==0) or (n%2==0 and p%2==0):
        print(min(p//2,(n-p)//2))
elif n%2==0 and p%2!=0:
        print(min(p//2,((n-p)//2)+1))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Wednesday, August 1, 2018

Viral Advertising : Algorithms - Implementation

#The solution in Python3 is as follows:


m = [2]
for i in range(int(input())-1):
    m.append(int(3*m[i]/2))
print(sum(m))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Sunday, July 29, 2018

Cats and a Mouse : Algorithms - Implementation

#The solution in Python3 is as follows:


for _ in range(int(input())):
    x,y,z=map(int,input().split())
    if x==y:
        print("Mouse C")
    elif x==z:print("Cat A")
    elif y==z:print("Cat B")
    elif (x>z and y<z) or (x<z and y>z):
        if abs(x-z)==abs(y-z):
            print("Mouse C")
        elif min(abs(x-z),abs(y-z))==abs(x-z):
            print("Cat A")
        else:
            print("Cat B")

    elif (x<z and y<z and x<y) or (x<z and y<z and x>y):
        a=max(x,y)
        if a==y:
            print("Cat B")
        else:
            print("Cat A")
    elif (x>z and y>z and y>x) or (x>z and y>z and y<x):
        b=min(x,y)
        if b==x:
            print("Cat A")
        else:
            print("Cat B")

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Monday, July 23, 2018

Counting Valleys : Algorithms - Implementation

#The solution in Python3 is as follows:


def countingValleys(n, steps):
    seaLevel = valley = 0

    for step in steps:
        if step == 'U':
            seaLevel += 1
        else:
            seaLevel -= 1
       
        if step == 'U' and seaLevel == 0:
            valley += 1
   
    return valley
n=int(input())
s=input()
print(countingValleys(n,s))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Wednesday, July 18, 2018

Utopian Tree : Algorithms - Implementation

#The solution in Python3 is as follows:


for _ in range(int(input())):
       n=int(input())
       height=1
       i=1
       while i<=n:
            if i%2!=0:
                  height=2*height
            else:
                  height+=1
            i+=1
       print(height)


#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Tuesday, July 17, 2018

The Hurdle Race : Algorithms - Implementation

#The solution in Python3 is as follows:


n,k=map(int,input().split())
a=list(map(int,input().split()))
b=max(a)
if k>b:
    print(0)
else:
    print(b-k)

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Monday, July 16, 2018

Designer PDF Viewer : Algorithms - Implementation

#The solution in Python3 is as follows:


a=list(map(int,input().split()))
s=input()
b=[]
alfa = "abcdefghijklmnopqrstuvwxyz"
rdict = dict([ (x[1],x[0]) for x in enumerate(alfa) ])
for i in s:
      b.append(a[rdict[i]])
print(len(b)*max(b))

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Angry Professor : Algorithms - Implementation

#The solution in Python3 is as follows:


for _ in range(int(input())):
       n,k=map(int,input().split())
       a=list(map(int,input().split()))
       s=sum(1 for number in a if number<=0)    #Count the no. of  -ve numbers.
       if s>=k:
             print("NO")
        else:
             print("YES")

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!

Wednesday, July 11, 2018

Beautiful Days at the Movies : Algorithms-Implementation

#The solution in Python is as follows:


i,j,k=map(int,input().split())
l=i
beauty=0
while l<=j:
      a=l
      b=str(a)[::-1]
      c=int(b)
      if (c-a)%k==0:
               beauty+=1
      l+=1
print(beauty)

#Keep visiting for more solutions of HackerRank problems in Python 3.Thank you!!!