hackerrank.com
-
hackerrank.com Practice>Python>Collections>DefaultDict Tutorialhackerrank.com 2019. 2. 10. 14:57
DefaultDict TutorialProblem link : https://www.hackerrank.com/challenges/defaultdict-tutorial/problem Difficulty : EasyTipProblem suggest to use defaultdict(), however, it seems that just using list is better wayOne loop for list m, as per each m, to find index of m from list nthis way is better to know index from list nSolution a = list(map(int, input().split())) n = a[0] m = a[1] ns = [] ms = ..
-
hackerrank.com Practice>Python>Itertools>Compress the String!hackerrank.com 2019. 2. 7. 21:43
Compress the String! TipThis is quite simple problem if you understand how to use groupby()Focus two variables(k and g) are iterated from groupby()As an example groupby('aaabb'), g is 'aaa', and k is 'a' Solution from itertools import groupby s = input() o = [(len(list(g)), int(k)) for k, g in groupby(s)] print(*o)
-
hackerrank.com Practice>Python>Sets>No Idea!hackerrank.com 2019. 2. 6. 16:18
No Idea! TipPlease utilize set() to check that n integers is in set A(or B)Actually, the numbers(n and m) is not matter for problemAs we can split and count each integer from input(), like belowinput().split()Create list from n integersCreate set A and set Bcheck each item in list is in set A or set B Solution # Enter your code here. Read input from STDIN. Print output to STDOUT n, m = input().s..
-
hackerrank.com Practice>Python>Strings>Merge the Tools!hackerrank.com 2019. 2. 4. 20:16
hackerrank.com Practice>Python>Strings>Merge the Tools! Merge the Tools! TipWe can solve this problem with setHowever, better way, is the using string replacementSubstring as per the length of kinput is spick the first character, and replace it to ''s.replace(s[0])Now, duplication of first character is resolveTo apply the way, to whole string, please see belows[0:j] + s1[j:].replace(s1[j-1], '')..
-
hackerrank.com Practice>Python>Strings>The Minion Gamehackerrank.com 2019. 2. 4. 20:04
hackerrank.com Practice>Python>Strings>The Minion Game 'The Minion Game' TipBasic approach should be substring, this is not regarding combination and permutationthe sequence of characters is not changedif input is BANits substrings are like belowB