aboutsummaryrefslogtreecommitdiff
path: root/challenge-221/eric-cheung/python/ch-1.py
blob: 5e479222720812a28975103958c3b04d2a835db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Example 1
## arrInputWords = ["cat", "bt", "hat", "tree"]
## strChars = "atach"

## Example 2
arrInputWords = ["hello", "world", "challenge"]
strChars = "welldonehopper"

arrUniqChar = list(set(strChars))
arrUniqCharCount = [strChars.count(charLoop) for charLoop in arrUniqChar]

arrOutputWords = []
nSumCharLength = 0

for strLoop in arrInputWords:
    arrCharCount = arrUniqCharCount[:]
    bIsFound = True

    for charLoop in strLoop:
        if not charLoop in arrUniqChar:
            bIsFound = False
            break

        nIndx = arrUniqChar.index(charLoop)

        if arrCharCount[nIndx] == 0:
            bIsFound = False
            break

        arrCharCount[nIndx] = arrCharCount[nIndx] - 1

    if bIsFound:
        arrOutputWords.append(strLoop)
        nSumCharLength = nSumCharLength + len(strLoop)

## print (arrOutputWords)
print (nSumCharLength)