English beggars
Description: Born a misinterpretation of this kata, your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last. For example: [1,2,3,4,5] for 2 beggars will return a result of [9,6], as the first one takes [1,3,5], the second c..
2022. 3. 16.
+1 Array
Description: Given an array of integers of any length, return an array that has 1 added to the value represented by the array. the array can't be empty only non-negative, single digit integers are allowed Return nil (or your language's equivalent) for invalid inputs. Examples For example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0]. [4, 3, 2, 5] would return [4, 3,..
2022. 3. 15.
Python _ 리스트 요소 개수 세기(dictionary, collections)
리스트에 어떤 요소의 개수를 파악해야하는 때가 있습니다. (특히 코딩테스트에서 사용할 일이 많습니다) 그래서 오늘은 요소 개수를 세는 방법을 정리해보고자 합니다. dictionary 사용 # 요소를 세고 싶은 리스트 >>> list = [1,2,3,4,5,5,5,5,5,1,1] # 빈 딕셔너리를 생성 >>> dict = {} # 요소가 딕셔너리에 있다면 += 1, 없다면 = 1 >>> for num in list: if num in dict: # dict.get(num)로 대체가능 dict[num] += 1 else: dict[num] = 1 # {요소(키): 개수(값)} 형태의 딕셔너리 생성 >>> dict {1: 3, 2: 1, 3: 1, 4: 1, 5: 5} 기본 딕셔너리를 사용하는 베이직한 방법입..
2022. 3. 6.