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

Game of Coins : Basic Programming - Implementation - Basics of Implementation

#The solution in Python3 is as follows:


ALICE = 'Alice'
BOB = 'Bob'
# Write your code here
def lolo(N):
    return ALICE
   

def init():
    T = input()
    for num_testcases in range(int(T)):
           A = int(input())
           x = lolo(A)
           print(x)
init()

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

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

Last Occurrence : Algorithms - Searching - Linear Search

#The solution in Python3 is as follows:


n,m=map(int,input().split())
a=list(map(int,input().split()))
if m in a:
    b=len(a) - a[::-1].index(m) - 1
    print(b+1)
else:
    print(-1)

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