← Back to challenges

Word Nests

PythonHardlanguage_fundamentalsstrings

Instructions

A word nest is created by taking a starting word, and generating a new string by placing the word inside itself. This process is then repeated.

Nesting 3 times with the word "incredible":

start  = incredible
first  = incre|incredible|dible
second = increin|incredible|credibledible
third  = increinincr|incredible|ediblecredibledible

The final nest is "increinincrincredibleediblecredibledible" (depth = 3).

Given a starting word and the final word nest, return the depth of the word nest.

Examples

word_nest("floor", "floor") ➞ 0

word_nest("code", "cocodccococodededeodeede") ➞ 5

word_nest("incredible", "increinincrincredibleediblecredibledible") ➞ 3

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.