Skip to content

Commit ca572be

Browse files
committed
Added medium problem
1 parent 633ed18 commit ca572be

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# MINIMUM CHARACTERS FOR WORDS
3+
4+
# O(N * L) time, N - no of words, L - length of longest word
5+
# O(C) space - lower bound, C - no of unique characters
6+
# o(N * L) space - upper bound, since there might be words having all same characters
7+
def minimumCharactersForWords(words):
8+
# Write your code here.
9+
characters = {}
10+
for word in words:
11+
temp = {}
12+
for letter in word:
13+
if letter not in temp:
14+
temp[letter] = 0
15+
temp[letter] += 1
16+
if letter not in characters or characters[letter] < temp[letter]:
17+
characters[letter] = temp[letter]
18+
19+
result = []
20+
for char in characters:
21+
for times in range(characters[char]):
22+
result.append(char)
23+
24+
return result

0 commit comments

Comments
 (0)