You've successfully subscribed to The Poor Coder | Hackerrank Solutions
Great! Next, complete checkout for full access to The Poor Coder | Hackerrank Solutions
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Hackerrank - Designer Door Mat Solution

Hackerrank - Designer Door Mat Solution

Beeze Aal
Beeze Aal

Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications:

  • Mat size must be X. ( is an odd natural number, and  is  times .)
  • The design should have 'WELCOME' written in the center.
  • The design pattern should only use |, . and - characters.

Sample Designs

  Size: 7 x 21 
---------.|.---------
------.|..|..|.------
---.|..|..|..|..|.---
-------WELCOME-------
---.|..|..|..|..|.---
------.|..|..|.------
---------.|.---------

Size: 11 x 33
---------------.|.---------------
------------.|..|..|.------------
---------.|..|..|..|..|.---------
------.|..|..|..|..|..|..|.------
---.|..|..|..|..|..|..|..|..|.---
-------------WELCOME-------------
---.|..|..|..|..|..|..|..|..|.---
------.|..|..|..|..|..|..|.------
---------.|..|..|..|..|.---------
------------.|..|..|.------------
---------------.|.---------------

Input Format

A single line containing the space separated values of  and .

Constraints

Output Format

Output the design pattern.

Sample Input

9 27

Sample Output

------------.|.------------
---------.|..|..|.---------
------.|..|..|..|..|.------
---.|..|..|..|..|..|..|.---
----------WELCOME----------
---.|..|..|..|..|..|..|.---
------.|..|..|..|..|.------
---------.|..|..|.---------
------------.|.------------

Solution in Python

#take rows and columns and convert both to integer using map function 
rows,columns = map(int,input().split())
#Middle row where "WELCOME" will be written
middle = rows//2+1
#Top part of door mat
for i in range(1,middle):
    #calculate number of .|. required and multiply with .|.
    center = (i*2-1)*".|."
    #Move our center pattern to center using string.center method and fill left and part with "-" 
    print(center.center(columns,"-"))
#print middle part welcome
print("WELCOME".center(columns,"-"))
#create bottom part in reverse order like we did in the top part
for i in reversed(range(1,middle)):
    center = (i*2-1)*".|."
    print(center.center(columns,"-"))

Another solution

x,y = map(int,input().split())
items = list(range(1,x+1,2))
items = items+items[::-1][1:]
for i in items:
    text= "WELCOME" if i == x else '.|.'*i
    print (text.center(y,'-'))