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!!!

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

MAXGRITH - Maximum Girth : Classical

#The solution in Python3 is as follows:


for _ in range(int(input())):
n = int(input())
print ((((n+1)*2)//3) % 1000000007)


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

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!!!

Soft Sort : Basic Programming - Implementation - Basics of Implementation

#The solution in Python3 is as follows:


if __name__ == '__main__':
    N = [0] * 1000000
    n = 1
    for i in range(1, 1000001):
        n = (n * i) % 1000000007
        N[i - 1] = n


    T = int(input())
    for t in range(0, T):
        n = int(input())
        print(3*(N[n - 1] + 1) % 1000000007)

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

Thursday, July 12, 2018

Little Jhool and psychic powers : Basic Programming - Implementation - Basics of Implementation

#The solution in Python3 is as follows:


b=input()
a='000000'
c='111111'
if a in b or c in b:
    print("Sorry, sorry!")
else:
    print("Good luck!")

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

Roy and Wobbly Numbers : Practice - Math

#The solution in Python3 is as follows:


import math
for _ in range(int(input())):
    n,k=list(map(int,input().split()))
    odd=math.ceil(k/9)
    even=k%9
    if even<=odd:
            if even!=0:
                even-=1
            else:
                even=9
                if k==81:
                    even-=1
       
    if k>81:
        print(-1)
    else:
        l=[]
        for i in range(n):
            if i%2==0:
                l.append(str(odd))
            else:
                l.append(str(even))
        print("".join(l))

#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!!!

Sunday, July 8, 2018

EC_CONB - Even Numbers : Classical

#The solution in Python is as follows:


for _ in xrange(int(raw_input())):
        n=int(raw_input())
        if n%2==0:
                a=bin(n)[2:]
                b=a[::-1]
                print int(b,2)
        else:
                print n


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

Thursday, July 5, 2018

SYNC13C - WHAT A CO-ACCIDENT : Classical

#The solution in Python 3 is as follows:


for _ in range(int(input())):
c1,c2=map(int,input().split())
if c1%2 and c2%2:
print('Ramesh')
else:
print('Suresh')


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

Tuesday, July 3, 2018

HANGOVER - Hangover : Classical

#The solution in Python 3 is as follows:


while True:
    c=float(input())
    n=2
    if c==0:
        break
    while c>0:
        c-=1.0/n
        n+=1
    print(n-2,'card(s)')


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

Monday, July 2, 2018

MIRRORED - Mirrored Pairs : Tutorial

#The solution in Python 3 is as follows:


b=[]
while True:
     x=input()
     if x=="  ":
            print("Ready")
            for i in range(len(b)):
                    print(b[i])
            break
    if x=='pq' or x=='qp' or x=='db' or x=='bd':
           b.append("Mirrored pair")
    else:
           b.append("Ordinary pair")


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

GERGOVIA - Wine trading in Gergovia : Classical

#The solution in Python 3 is as follows:


while True:
t=0
w=0
if int(input()) == 0:
               break
for a in list(map(str,input().split())):
t+= int(a)
w+= abs(t)
print(w)


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

Sunday, July 1, 2018

VHELSING - Van Helsings gun : Classical

#The solution in Python 3 is as follows:


import math
for _ in range(int(input())):
 r=int(input())
 print('%.4f' % (8*(2-(math.sqrt(2)))*(pow(r,3))))


#Visit this link for detailed information.

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