We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
We need to print a door mat design pattern given two inputs n (rows) and m (columns).
- The pattern must have WELCOME centered in the middle row.
- The top half and bottom half must be symmetric with motifs made of .|..
- The total width m is guaranteed to be 3 * n.
My Approach
Top Half:
For each row before the middle, the motif count grows as (2 * height + 1).
Each line is padded with - on both sides to keep the width = m.
By controlling motif counts in both halves, the design is symmetric around the middle.
Code
# Enter your code here. Read input from STDIN. Print output to STDOUTn,m=map(int,input().split())dash='-'center='.|.'welcome='WELCOME'dash_mul_top=3*(n//2)dash_mul_bottom=3forheightinrange(0,n):ifheight<n//2:# Top halfprint(dash*dash_mul_top,end="")print(center*(2*height+1),end="")print(dash*dash_mul_top,end="")dash_mul_top-=3print()elifheight==n//2:# Middle rowdash_mul_middle=(m-len(welcome))//2print(dash*dash_mul_middle,end="")print(welcome,end="")print(dash*dash_mul_middle,end="")print()else:# Bottom halfprint(dash*dash_mul_bottom,end="")print(center*(2*((n-1)-height)+1),end="")print(dash*dash_mul_bottom,end="")dash_mul_bottom+=3print()
Designer Door Mat
You are viewing a single comment's thread. Return to all comments →
Solution for Designer Door Mat Problem
Problem
We need to print a door mat design pattern given two inputs
n
(rows) andm
(columns).- The pattern must have
WELCOME
centered in the middle row.- The top half and bottom half must be symmetric with motifs made of
.|.
.- The total width
m
is guaranteed to be3 * n
.My Approach
Top Half:
(2 * height + 1)
.-
on both sides to keep the width =m
.Middle Row:
WELCOME
centered with dashes.Bottom Half:
(2 * ((n-1) - height) + 1)
.Symmetry Guarantee:
Code
Example
Input:
Output:
Complexity Analysis
Time Complexity:
n
lines, and each line is of lengthm
.Space Complexity:
n
orm
.✅ The solution is clean, efficient, and guaranteed to run within constraints.