

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Recursion
incomplete
2: Recursion Review
incomplete
3: Zipmap
incomplete
4: Recursion Quiz
incomplete
5: Nested Sum
incomplete
6: Recursion Review
incomplete
7: Recursion on a Tree
incomplete
8: Dangers of Recursion
incomplete
9: Recursion Practice
incomplete
10: Recursion Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In Doc2Doc, we might have documents nested inside other documents, forming a kind of tree. You know how crazy .docx files can get...
Anyway, we want to find out how deeply nested a given document is.
Complete the count_nested_levels function. It takes a dictionary of nested documents, the target document ID, and the current level of the document.
In this dictionary, the document with ID 3 is nested 2 levels deep. Document 2 is nested 1 level deep.
nested_documents: dict[int, dict] = {1: {3: {}}, 2: {}}
The -1 return value is the "not found" signal. If a recursive call returns -1, the target isn't in that branch.