Number Pattern

A high-security meeting has been arranged. Tables for the delegates and security personnel have been arranged. A total of ‘N’ rows of tables has been set up. The first row has one table, the second row has two, and so on. To ensure maximum security, the tables on either end of each row have been assigned for security personnel each. If there is only one table in a row, it will be assigned to a security personnel. The tables assigned for security personnel will host exactly one security personnel each. All the other tables will host two guests each.

You are given an integer ‘N’, which denotes the number of rows., You are supposed to print the table pattern indicating the number of guests or security personnel at each table. In other words, print the number of people in each table.

For example, if the number of rows are 4, the table pattern is as follows:
1
11
121
1221
Input Format:
The first line contains ‘T’, denoting the number of test cases.

Each test case contains a single integer ‘N’, denoting the number of rows.
Output Format:
For each test case, print 'N' strings denoting the pattern.
Note:
You are not required to print the expected output. It has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= N <= 10^3

Where ‘N’ is the number of lines.

Time Limit: 1 sec
CodingNinjas
author
2y

Step 1 : For rows of rectangle ran the outer loop from 1 to rows.
Step 2 : For column of rectangle run the inner loop from 1 to columns.
Step 3 : Print star for first or last row or for first or last co...read more

CodingNinjas
author
2y
Brute Force

The idea here is to traverse all the rows and, for each row, print the suitable character at any particular table.

The steps are as follows:

  • We define a ‘RESULT’ matrix.
  • We traverse from ‘i’ =...read more
Help your peers!
Add answer anonymously...
S&P Global Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter