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.
- Prepare
- Python
- Strings
- Designer Door Mat
- Discussions
Designer Door Mat
Designer Door Mat
Sort by
recency
|
1821 Discussions
|
Please Login in order to post a comment
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.
n,m = map(int,((input()).split(' ')))
for i in range(n//2): pt = '.|.'*(2*i+1) print(pt.center(m,'-'))
print('WELCOME'.center(m,'-'))
for i in range((n//2)-1,-1,-1): pt = '.|.'*(2*i+1) print(pt.center(m,'-'))
N, M = list(map(int,input().split())) wlen = len('WELCOME') j = 0 for i in range(N): # for j in range(M): if i < (N-1)/2: print('-'*int((M-(1+i*2)3)/2) + '.|.'(1+i*2) + '-'*int((M-(1+i*2)*3)/2)) elif i==(N-1)/2: print('-'*int((M-7)/2) + 'WELCOME' + '-'int((M-7)/2)) else: # i>=(N+1)/2: print('-'(3+j*3)+ '.|.'*(N-2-2*j)+'-'*(3+j*3)) j +=1