Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Alphabet Rangoli problem solution in python

YASH PAL, 31 July 2024

In this HackerRank Alphabet Rangoli problem solution, 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 creation of patterns.) 

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

HackerRank Alphabet Rangoli solution in python

Problem solution in Python 2 programming.

from copy import deepcopy
N = int(raw_input())
row = 2 * (N - 1) + 1
col = (N - 1) * 4 + 1
arr = ['-'] * col
res = []
for _ in xrange(row): res.append(deepcopy(arr))
mr = row / 2
mc = col / 2
for i in xrange(mr + 1):
    ch = ord('a') + i
    for j in xrange(N - i):
        res[mr - i][mc - 2 * j] = chr(ch + j)
        res[mr - i][mc + 2 * j] = chr(ch + j)
        res[mr + i][mc - 2 * j] = chr(ch + j)
        res[mr + i][mc + 2 * j] = chr(ch + j)
for r in res:
    print ''.join(r)


Problem solution in Python 3 programming.

def print_rangoli(size):
    alpha = "abcdefghijklmnopqrstuvwxyz"
    data = [alpha[i] for i in range(n)]
    items = list(range(n))
    items = items[:-1]+items[::-1]
    for i in items:
        temp = data[-(i+1):]
        row = temp[::-1]+temp[1:]
        print("-".join(row).center(n*4-3, "-"))

Problem solution in pypy programming.

import string
def print_rangoli(size):
    alpha = string.ascii_lowercase
    n = size
    L = []
    for i in range(n):
        s = "-".join(alpha[i:n])
        L.append((s[::-1]+s[1:]).center(4*n-3, "-"))
    print('n'.join(L[:0:-1]+L))

Problem solution in pypy3 programming.

import string
alpha = string.ascii_lowercase

n = int(input())
L = []
for i in range(n):
    s = "-".join(alpha[i:n])
    L.append((s[::-1]+s[1:]).center(4*n-3, "-"))
print('n'.join(L[:0:-1]+L))

coding problems solutions Hackerrank Problems Solutions Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes