DEV Community

loading...

Discussion on: Daily Challenge #260 - Subtract the Sum

Collapse
vidit1999 profile image
Vidit Sarkar

Here is a solution,

return "apple";
Collapse
vidit1999 profile image
Vidit Sarkar

And here is a recursive Python solution,

fruits = [
    "kiwi",
    "pear",
    ....
    "melon",
    "pineapple",
    "apple",
    "pineapple"
]

def SubtractSum(number : int) -> str:
    temp = number - sum(map(int ,str(number)))
    if(1 <= temp <= 100):
        return fruits[temp-1]
    return SubtractSum(temp)