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-

{tocify} $title={Table of Contents}

Default Arguments Python HackerRank Solution

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


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


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
# Direct Link:
# Difficulty: Easy
# Max Score: 20
# Language: Pypy 3

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

#Alphabet Rangoli in Python - Hacker Rank Solution
def print_rangoli(size):
    # your code goes here
    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, "-"))

if __name__ == '__main__':
    n = int(input())
#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!

Post a Comment

Previous Post Next Post