Hackerrank - Triangle Quest Solution
1 min read

Hackerrank - Triangle Quest Solution

You are given a positive integer . Print a numerical triangle of height like the one below:
Hackerrank - Triangle Quest Solution

You are given a positive integer . Print a numerical triangle of height  like the one below:

1
22
333
4444
55555
......

Can you do it using only arithmetic operations, a single for loop and print statement?

Use no more than two lines. The first line (the for statement) is already written for you. You have to complete the print statement.

Note: Using anything related to strings will give a score of 0.

Input Format
A single line containing integer, .

Constraints
1<=N<=9

Output Format
Print N-1 lines as explained above.

Sample Input

5

Sample Output

1
22
333
4444

Solution in Python

Pure mathematics

for i in range(1,5):
    print((10**(i)//9)*i)

Using python lambda, map, range and sum functions

for i in range(1,int(input())):
    print(i*sum(map(lambda x:10**x, range(i))))

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×