GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Thursday, 26 May 2022

[Solution] Infinity Staircase CodeChef Solution | CodeChef Problem Solution 2022

You are climbing an infinity staircase, which (as its name suggests) has an infinite number of steps. You are currently standing at the 1st step, and you would like to reach the N-th step. When standing at the i-th step, you can make one of the following three moves:

  • Move to step i+1
  • Move to step i+2
  • Move to step i+3

However, you can't make the same move twice in a row.

For example, suppose you reach the 7th step from the 4th step using the third move. Then, from the 7th step, you can move to either the 8th or the 9th step (using the 1st or 2nd move) — but you can't move to the 10th step (because you would use the third move twice in a row). 

Solution Click Below:-  CLICK HERE

Now suppose you choose the 1st move and move to the 8th step. On your next move, you cannot move to the 9th step, but you can move to either the 10th or the 11th step.

Under these conditions, find the minimum number of moves you need to reach the N-th step.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of a single line containing one integer, N.

Output Format

  • For each test case, print on a new line the minimum number of moves required to reach the N-th step.

Constraints

  • 1T105

No comments:

Post a Comment