Python
-
Practice>Python>Sets>Check Strict Supersethackerrank.com 2019. 3. 9. 05:30
hackerrank.comCheck Strict SupersetProblem link : https://www.hackerrank.com/challenges/py-check-strict-superset/problemDifficulty : Easy TipWe can use difference(), however, there is a method to check that it is super setissuperset()Solution A = set(input().split(' ')) def d(): cnt = int(input()) for _ in range(cnt): B = set(input().split(' ')) if A.issuperset(B) is False: return False return T..
-
Practice>Python>Sets>Check Subsethackerrank.com 2019. 3. 9. 05:13
hackerrank.comCheck SubsetProblem link : https://www.hackerrank.com/challenges/py-check-subset/problemDifficulty : EasyTipJust use difference(), it is all you should know to resolve it Solution cnt = int(input()) for _ in range(cnt): input() A = set(input().split(' ')) input() B = set(input().split(' ')) a1 = A.difference(B) if len(a1) > 0: print(False) else: print(True)
-
Practice>Python>Sets>The Captain's Roomhackerrank.com 2019. 3. 8. 13:36
hackerrank.comThe Captain's RoomProblem link : https://www.hackerrank.com/challenges/py-the-captains-room/problemDifficulty : Easy TipProblem description is a bit longPoint is that captain's room number is appeared only onceOther room number is repeatedCreate defatultdict with lamda: 0room number is a key of dict, and +1 when the number is appearedcheck what key is only appeared one timeSolution..
-
Practice>Python>Math>Triangle Questhackerrank.com 2019. 3. 7. 12:58
hackerrank.comTriangle QuestProblem link : https://www.hackerrank.com/challenges/python-quest-1/problemDifficulty : Medium Tip1 -> 1 / 1 -> 122 -> 22/2 -> 11333 -> 333/3 -> 1114444 -> 4444/4 -> 1111This is a first idea10 ** 1 // 9 -> 110 ** 2 // 9 -> 1110 ** 3 // 9 -> 11110 ** 4 // 9 -> 1111This is a second idea Solution for i in range(1, int(input())): print(10**i//9 * i)
-
Practice>Python>Math>Integers Come In All Sizeshackerrank.com 2019. 3. 7. 12:48
hackerrank.comIntegers Come In All SizesProblem link : https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes/problemdifficulty : Easy Tipint(input())a**bThey are all we should know to solve it Solution a = int(input()) b = int(input()) c = int(input()) d = int(input()) print(a**b + c**d)
-
Practice>Python>Debugging>Words Scorehackerrank.com 2019. 3. 7. 07:31
hackerrank.comWords ScoreProblem link : https://www.hackerrank.com/challenges/words-score/problemDifficulty : Medium Tipit seems that problem is a bit complex, however, it's pointing only one thingWe understand the difference between '++' and '+='In C/C++, they are almost same functionality, however, in python, they are differentMost of legacy code is fine, just fix only few characters regarding..
-
Practice>Python>Itertools>Maximize It!hackerrank.com 2019. 3. 7. 07:20
hackerrank.comMaximize It!Problem link : https://www.hackerrank.com/challenges/maximize-it/problemDifficultiy : Hard TipCartesian product is a key to solve this problem, from 'from itertools import product'Don;t miss that the first item in each K line, is # of NiDo '%' to sum of each itemSave maximum result of '%' Solution from itertools import product lines, mod = map(int, input().split(' ')) i..
-
Practice>Python>Itertools>Iterables and Iteratorshackerrank.com 2019. 3. 4. 13:15
Iterables and IteratorsProblem link : https://www.hackerrank.com/challenges/iterables-and-iterators/problemDifficulty : Medium TipAs we can see from problem description, it's regarding combinationWe might be confused a bit due to that 'a' is appeared only once, or multipleIf 'a' appeared only once, we can resolve it simplyHowever, a appeared in multiple timeswe should generate all combinationand..