Skip to content

Latest commit

 

History

History
53 lines (30 loc) · 837 Bytes

Scramblies.md

File metadata and controls

53 lines (30 loc) · 837 Bytes

CodeWars Python Solutions


Scramblies

Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.

Notes:

  • Only lower case letters will be used (a-z). No punctuation or digits will be included.
  • Performance needs to be considered

Input strings s1 and s2 are null terminated.

Examples

scramble('rkqodlw', 'world') ==> True
scramble('cedewaraaossoqqyt', 'codewars') ==> True
scramble('katas', 'steak') ==> False

Given Code

for c in set(s2):
    pass

Solution

for c in set(s2):
        if s1.count(c) < s2.count(c):
            return False
    return True

See on CodeWars.com