Alphabet Rangoli in Python HackerRank Solution

Alphabet Rangoli - Python HackerRank Solution

Hello Friends, How are you? Today I am going to solve the HackerRank Alphabet Rangoli Problem in Python with a very easy explanation. In this article, you will get one or more than one approaches to solving this problem. So let's start-

HackerRank Python Alphabet Rangoli Solution - Problem Statement

You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on the creation of patterns.)

Different sizes of alphabet rangoli are shown below:

#size 3 ----c---- --c-b-c-- c-b-a-b-c --c-b-c-- ----c---- #size 5 --------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e-------- #size 10 ------------------j------------------ ----------------j-i-j---------------- --------------j-i-h-i-j-------------- ------------j-i-h-g-h-i-j------------ ----------j-i-h-g-f-g-h-i-j---------- --------j-i-h-g-f-e-f-g-h-i-j-------- ------j-i-h-g-f-e-d-e-f-g-h-i-j------ ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j---- --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j-- j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j-- ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j---- ------j-i-h-g-f-e-d-e-f-g-h-i-j------ --------j-i-h-g-f-e-f-g-h-i-j-------- ----------j-i-h-g-f-g-h-i-j---------- ------------j-i-h-g-h-i-j------------ --------------j-i-h-i-j-------------- ----------------j-i-j---------------- ------------------j------------------ {codeBox}

The centre of the rangoli has the first alphabet letter a, and the boundary has the Nth alphabet letter (in alphabetical order).

Function Description

Complete the rangoli function in the editor below.

rangoli has the following parameters:

• int size: the size of the rangoli

Returns

• string: a single string made up of each of the lines of the rangoli separated by a newline character (\n)

Input Format

Only one line of input containing N, the size of the rangoli.

Constraints

0 < size < 27

Sample Input 0

5 {codeBox}

Sample Output 0

--------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e-------- {codeBox}

Python Alphabet Rangoli - Hacker Rank Solution

1st Approach: Alphabet Rangoli HackerRank Python Solution

``````# ========================
#       Information
# ========================

# Name: Alphabet Rangoli in Python HackerRank
# Difficulty: Easy
# Max Score: 20
# Language: Pypy 3

# ========================
#         Solution Start
# ========================

#Alphabet Rangoli in Python - Hacker Rank Solution

def print_rangoli(size):
import string
design = string.ascii_lowercase

L = []
for i in range(n):
s = "-".join(design[i:n])
L.append((s[::-1]+s[1:]).center(4*n-3, "-"))

print('\n'.join(L[:0:-1]+L))

if __name__ == '__main__':
n = int(input())
print_rangoli(n)

#Alphabet Rangoli in Python - Hacker Rank Solution END
# MyEduWaves``````

Disclaimer: The above Problem (Alphabet Rangoli in Python) is generated by Hackerrank but the Solution is Provided by MyEduWaves. This tutorial is only for Educational and Learning purposes. Authority if any queries regarding this post or website fill out the contact form.

I hope you have understood the solution to this HackerRank Problem. All these three solutions will pass all the test cases. Now visit Alphabet Rangoli in Python Hackerrank Problem and try to solve it again.

All the Best!