Hacker Rank SQL

Draw The Triangle 2 Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | Draw The Triangle 2 Solution

Also Visit:  Draw The Triangle 1 Solution



P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):

* * 
* * * 
* * * * 
* * * * *

Write a query to print the pattern P(20).

Solution – Draw The Triangle 2

MySQL Code
set @row := 0;
select repeat('* ', @row := @row + 1) 
from information_schema.tables where @row < 20


What is a star in programming ?

In any programming language, star patterns are a common pattern widely used because it helps to improve logical thinking and flow control knowledge. You must use two or three loops to create a star pattern in the C language. The number of loops depends on the pattern that you need to create. For pattern, a minimum of two is used i.e. one for a row and one for a column. The First loop is called an outer loop that shows the rows, and the second loop is called an inner loop that shows columns.

Star patterns are a series of * or any other character used to create some pattern or any geometrical shape such as – square, triangle(Pyramid), rhombus, heart etc. These patterns are often prescribed by many programming books and are best for practicing flow control statement.

Many programmers around world extremely recommended pattern problems, to enhance logical thinking capabilities. As a novice programmer you must practice these patterns to get a good hands on logical thinking and program flow control.


Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.