Posts

Showing posts with the label Hackerrank

Challenge - #57 - Collections.deque()

# Enter your code here. Read input from STDIN. Print output to STDOUT from  collections  import  deque d = deque() for  i  in   range ( int ( input ())):     inp =  input ()      if  inp ==  "pop" :         d.pop()      elif  inp ==  "popleft" :         d.popleft()      else :         command , value = inp.split()         value =  int (value)          if  command ==  "append" :             d.append(value)          else :  ...

Challenge - #56 - Symmetric Difference

  # Enter your code here. Read input from STDIN. Print output to STDOUT M =  int ( input ()) setM =  set ( map ( int ,  input ().split())) N =  int ( input ()) setN =  set ( map ( int ,  input ().split())) result = setM.symmetric_difference(setN) print (* sorted (result),sep= "\n" )

Challenge - #54 - Set .intersection() Operation

# Enter your code here. Read input from STDIN. Print output to STDOUT eng =  int ( input ()) eng_roll =  set ( map ( int ,  input ().split())) french =  int ( input ()) french_roll =  set ( map ( int ,  input ().split())) print ( len (eng_roll.intersection(french_roll)))

Challenge - #44 - Array Mathematics

 import numpy n,m = map(int, input().split()) A = numpy.array([list(map(int, input().split())) for i in range(n)]) B = numpy.array([list(map(int, input().split())) for i in range(n)]) print(A+B,A-B,A*B,A//B,A%B,A**B,sep='\n')

Challenge - #41 - set.add()

# Enter your code here. Read input from STDIN. Print output to STDOUT country_set =  set () for  i  in   range ( int ( input ())):     country_set.add( input ()) print ( len (country_set))

Challenge - #40 - No Idea!

  n,m =  map ( int ,  input ().split()) array =  list ( map ( int ,  input ().split())) set_a =  set ( map ( int ,  input ().split())) set_b =  set ( map ( int ,  input ().split())) happiness =  0   for  i  in  array :      if  i  in  set_a :         happiness +=  1      elif  i  in  set_b :         happiness -=  1      else  :          pass print (happiness)

Challenge - #39 - Symmetric Difference

  # Enter your code here. Read input from STDIN. Print output to STDOUT m =  int ( input ()) m_set =  set ( map ( int ,  input ().split())) n =  int ( input ()) n_set =  set ( map ( int ,  input ().split())) m_diff_n = m_set.difference(n_set) n_diff_m = n_set.difference(m_set) result =  list (m_diff_n) +  list (n_diff_m) sorted_result =  sorted (result) print (*sorted_result,sep =  '\n' )

Challenge - #37 - Triangle Quest 2

for  i  in   range ( 1 , int ( input ())+ 1 ):  #More than 2 lines will result in 0 score. Do not leave a blank line also      print  ((( 10 **i)// 9 )** 2 )

Challenge - #36 - Find Angle MBC

  # Enter your code here. Read input from STDIN. Print output to STDOUT import  math AB =  int ( input ()) BC =  int ( input ()) tita = (math.atan(AB/BC)) tita_to_degree =  round (math.degrees(tita)) print (tita_to_degree, chr ( 176 ),sep =  '' )

Challenge - #35 - Polar Coordinates

  # Enter your code here. Read input from STDIN. Print output to STDOUT import  cmath z =  complex ( input ()) r , phi = cmath.polar(z) print (r,phi,sep =  '\n' )

Challenge - #34 - Default Dict Tutorial

 from collections import defaultdict d = defaultdict(list) n,m = list(map(int, input().split())) for i in range(n):     d[input()].append(i+1) for i in range(m):     print(' '.join(map(str, d[input()])) or -1)

Challenge - #33 - collections.Counter()

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  collections  import  Counter no_of_shoes =  int ( input ()) size_lst =  map ( int ,  input ().split()) no_of_customers =  int ( input ()) shoes = Counter(size_lst) income =  0 for  i  in   range (no_of_customers):     size, price =  map ( int ,  input ().split())      if  shoes[size]:         income += price         shoes[size] -=  1 print (income)

Challenge - #32 - Compress The String!

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  itertools  import  groupby result = [( len ( list (c)), int (k))  for  k,c  in  groupby( input ())] print (*result)

Challenge - #31 - itertools.combinations_with_replacement

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  itertools  import  combinations_with_replacement s, k =  input ().split() k =  int (k) for  i  in   list (combinations_with_replacement( sorted (s), k)):      print ( '' .join(i))

Challenge - #30 - itertools.combinations()

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  itertools  import  combinations s , k =  input ().split() k =  int (k) for  i  in   range ( 1 , k+ 1 ):      for  j  in   list (combinations( sorted (s),i)):          print ( '' .join(j))

Challenge - #29 - itertools.permutations()

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  itertools  import  permutations s , n  =  input ().split() for  i  in   list (permutations( sorted (s), int (n))):      print ( '' .join(i),end =  '\n' )

Challenge - #28 - itertools.product()

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  itertools  import  product A =  list ( map ( int ,  input ().split())) B =  list ( map ( int ,  input ().split())) for  i  in   list (product(A,B)):      print (i, end =  ' ' )

Challenge - #27 - Merge The Tools!

  def  merge_the_tools(string, k):      # your code goes here      for  i  in   range ( 0 , len (string), k):         t = string[i:i+k]         u =  set ()          for  j  in  t:              if  j  not   in  u:                  print (j,end =  '' )                 u.add(j)          print () if  __name__ ==  '__main__' :     string, k =  input (),  int ( input ())     merge_the_tool...

Challenge - #26 - The Minion Game

  def  minion_game(string):      # your code goes here     vowel =  'AEIOU'     ks =  0   # ks - kevin score     ss =  0   # ss - stuart score      for  i  in   range ( len (s)):          if  s[i]  in  vowel :             ks += ( len (s)-i)          else :             ss +=  len (s)-i           if  ks > ss :          print (f "Kevin {ks}" )      elif  ks < ss :    ...