Monday, March 18, 2019

Q:17 - Shortest distance to a character

Given a string S and a character C, return an array of integers representing the shortest distance from the current character in S to C.

Notes
All letters will be lowercase.
If the string is empty, return an empty array.
If the character is not present, return an empty array.
Examples
shortest_to_char("lovecodewars", "e") == [3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4]
shortest_to_char("aaaabbbb", "b") == [4, 3, 2, 1, 0, 0, 0, 0]
shortest_to_char("", "b") == []
shortest_to_char("abcde", "") == []

Wednesday, February 20, 2019

Q:16 Get the expected output from the given dictionary

Input = [
{"subject" : "Hello", "message": "World"},
{"subject" : "Hello", "message": "Stranger!"},
{"subject" : "Hello", "message": "Stranger!"},
{"subject" : "Welcome", "message": "Python"}
]

Output:
{'Hello': ['World', 'Stranger!', 'Stranger!'], 'Welcome': ['Python']}