Ninja's Pattern with Powers of 2

Ninja, who loves playing with numbers, sets out to arrange numbers within 'N' rows. The unique arrangement follows these rules: the first row contains 1 number, the second row contains 2 numbers, and the third, 4 numbers, continuing this pattern of powers of 2.

He fills these patterns with numbers in increasing sequence, beginning from 1 up to 9, and upon reaching 9, recycles back to 1.

Your task is to produce the pattern for a given number 'N' of rows.

Example:

Input:
T = 1
N = 4
Output:
1
23
4567
89123456
Constraints:
  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 15

Time Limit: 1 sec

AnswerBot
4mo

Generate a pattern of numbers in rows following a powers of 2 sequence with numbers 1 to 9, recycling back to 1.

  • Start with 1 number in the first row, 2 numbers in the second row, 4 numbers in the thir...read more

Help your peers!
Select
Add answer anonymously...
RadiSys Software Engineer 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