Count Ways to Complete Journey in Triangular Pyramid

Given a triangular pyramid with vertices marked as ‘O’, ‘X’, ‘Y’, and ‘Z’, and an integer 'N', you need to calculate the number of ways Bob can start at ‘O’, take exactly 'N' steps, and return to ‘O’. Each step allows movement to any adjacent vertex.

You must return the result modulo 1000000007 as the output can be very large.

Input:

The input contains multiple test cases. Each test case provides:

  • An integer ‘T’ denoting the number of test cases.
  • For each test case, an integer ‘N’ indicating the number of steps.

Output:

For each test case, output the number of ways as a single integer, each on a new line for each test case.

Example:

Input:
T = 3
N = 1
N = 2
N = 3
Output:
0
3
6
Explanation:

- For ‘N’=1, there are 0 ways to return to ‘O’ in one step.
- For ‘N’=2, valid sequences: O->X->O, O->Y->O, O->Z->O, totaling 3 ways.
- For ‘N’=3, valid sequences: O->X->Y->O, O->X->Z->O, O->Y->X->O, O->Y->Z->O, O->Z->X->O, O->Z->Y->O, totaling 6 ways.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 10000
AnswerBot
4mo

Calculate the number of ways to complete a journey in a triangular pyramid starting and ending at a specific vertex after taking a certain number of steps.

  • Use dynamic programming to calculate the numb...read more

Help your peers!
Select
Add answer anonymously...

Oyo Rooms Software Developer interview questions & answers

A Software Developer was asked Q. Given the head of a singly linked list and two integers m and n, reverse the nod...read more
A Software Developer was asked Q. Merge sort algorithm and divide array in the chunks
A Software Developer was asked Q. Position of Right Most Set Bit Determine the position of the rightmost set bit i...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Given the head of a singly linked list and two integers m and n, reverse the nod...read more
A Software Developer was asked Q2. Merge sort algorithm and divide array in the chunks
A Software Developer was asked Q3. Position of Right Most Set Bit Determine the position of the rightmost set bit i...read more
Oyo Rooms Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits