LPS-42295 TDD: Add a unit test first
LPS-42295 Add runtime measurement
LPS-42295 Major refactor: remove recursion and use iterative DFS algorithm
LPS-42295 Move logic to a protected method - no changes
LPS-42295 Add thread local caching
LPS-42295 Source formatting - no logic changes