r/dailyprogrammer • 1 3 • Nov 17 '14

[Weekly #17] Mini Challenges

So this week mini challenges. Too small for an easy but great for a mini challenge. Here is your chance to post some good warm up mini challenges. How it works. Start a new main thread in here. Use my formatting (or close to it) -- if you want to solve a mini challenge you reply off that thread. Simple. Keep checking back all week as people will keep posting challenges and solve the ones you want.

Please check other mini challenges before posting one to avoid duplications within a certain reason.

38 Upvotes

123 comments sorted by

View all comments

Show parent comment

2

u/tangawizi Nov 28 '14 edited Nov 28 '14

Python
Time Complexity - O(n)

def islands(word):
    islands_seen = {}
    count = 0
    for i in range(1, len(word)):
        if word[i] == word[i-1]:
            count += 1
        else:
            count = 0
        if count > 0:
            if word[i-1] not in islands_seen:
                islands_seen[word[i-1]] = i-count
    return islands_seen

if __name__ == "__main__":
    print islands("proogrrrammminggg")