Interview Query

Integer String Addition

2
Have you seen this question before?

Write a Python function that adds together all combinations of adjacent integers of a given string of integers named int_str.

Example 1:

Input:

int_str = '12'

Output:

def int_str_addition -> 1 + 2 + 12 = 15

Example 2:

Input:

int_str = '123'

Output:

def int_str_addition(int_str) -> 1 + 2 + 3 + 12 + 23 + 123 = 164
#in this case, 13 is not part of our sum as 1 and 3 are not adjacent in '123'
Next question: Replace Words with Stems
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code