[HackerRank][SQL(Oracle)] Draw The Triangle 1, 2

728x90

 

■  [Alternative Queries]  Draw The Triangle 1

https://www.hackerrank.com/challenges/draw-the-triangle-1/problem?isFullScreen=true 

Q.

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).

A.

SELECT RPAD('* ', (20-LEVEL+1)*2, '* ') FROM DUAL CONNECT BY LEVEL <= 20; -- RPAD('*', (20-LEVEL+1)*2, ' *')

 


■  [Alternative Queries]  Draw The Triangle 2

https://www.hackerrank.com/challenges/draw-the-triangle-2/problem?isFullScreen=true 

Q.

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).

A.

SELECT RPAD('* ', LEVEL*2, '* ') FROM DUAL CONNECT BY LEVEL <= 20; -- RPAD('*', LEVEL*2, ' *')

 

 

반응형