물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Length of missing array

BEstyle 2022. 10. 24. 13:21

DESCRIPTION:

You get an array of arrays.
If you sort the arrays by their length, you will see, that their length-values are consecutive.
But one array is missing!


You have to write a method, that return the length of the missing array.

Example:
[[1, 2], [4, 5, 1, 1], [1], [5, 6, 7, 8, 9]] --> 3

If the array of arrays is null/nil or empty, the method should return 0.

When an array in the array is null or empty, the method should return 0 too!
There will always be a missing element and its length will be always between the given arrays.


def get_length_of_missing_array(arr):
    if arr==[]:
        return 0
    if arr==None:
        return 0
    if len(arr)==0:
        return 0
    alist=[]
    for i in arr:
        if i==None or i==[]:
            return 0
        else:
            alist.append(len(i))
    for i in range(min(alist),max(alist)):
        if i not in alist:
            return i

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Decipher this!  (0) 2022.10.25
Matrix Addition  (0) 2022.10.24
Kebabize  (0) 2022.10.24
Pascal's Triangle  (0) 2022.10.21
Tic-Tac-Toe Checker  (0) 2022.10.21