Untitled

mail@pastecode.io avatar
unknown
python
16 days ago
742 B
3
Indexable
Never
def findOdd(series):
    def get_differences(word):
        # Calculate differences between consecutive letters in a word
        return tuple(ord(word[i + 1]) - ord(word[i]) for i in range(len(word) - 1))

    # Get differences for all strings in the series
    diff_series = [get_differences(word) for word in series]

    # Create a dictionary to count occurrences of each difference pattern
    diff_count = {}
    for diff in diff_series:
        if diff in diff_count:
            diff_count[diff] += 1
        else:
            diff_count[diff] = 1

    # Find the odd one out by looking for the difference that occurs only once
    for i, diff in enumerate(diff_series):
        if diff_count[diff] == 1:
            return series[i]
Leave a Comment