Count Ways to travel Triangular Pyramid — Asked in Microsoft and Amazon Interview

Problem Statement :

1
0
2
3

Explanation of given Test Cases :

For the first test case:
There is no way we can start from ‘O’ and end up at ‘O’ because we will be either on ‘X’, ’Y’ or ‘Z’. Hence 0 ways.

For the second test case:
The possible ways are from ‘O’ we go to ‘X’ then back to ‘O’. Similarly for ‘Y’ and ‘Z’. Hence 3 ways.

Approach :

Code :

Thanks for Reading

Upskilling students for tech placements!