Posts

Showing posts from June, 2021

Collections.OrderedDict() Hackerrank Solution

  collections.OrderedDict An  OrderedDict  is a dictionary that remembers the order of the keys that were inserted first. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Example Code >>> from collections import OrderedDict >>> >>> ordinary_dictionary = {} >>> ordinary_dictionary['a'] = 1 >>> ordinary_dictionary['b'] = 2 >>> ordinary_dictionary['c'] = 3 >>> ordinary_dictionary['d'] = 4 >>> ordinary_dictionary['e'] = 5 >>> >>> print ordinary_dictionary {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} >>> >>> ordered_dictionary = OrderedDict() >>> ordered_dictionary['a'] = 1 >>> ordered_dictionary['b'] = 2 >>> ordered_dictionary['c'] = 3 >>> ordered_dictionary['d'] = 4 >>> ordered_dicti...

No Idea ! Hackerrank Solution

  There is an array of     integers. There are also     disjoint sets ,     and   , each containing     integers. You like all the integers in set     and dislike all the integers in set   . Your initial happiness is   . For each     integer in the array, if   , you add     to your happiness. If   , you add     to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end. Note:  Since   and   are sets, they have no repeated elements. However, the array might contain duplicate elements. Constraints Input Format The first line contains integers   and   separated by a space. The second line contains   integers, the elements of the array. The third and fourth lines contain   integers,   and  , respectively. Output Format Output a single integer, your total happines...