Designer Door Mat

Sort by

recency

|

1821 Discussions

|

  • + 0 comments
    if __name__ == '__main__':
        height, width = map(int, input().split(" "))
        wcenter = int(width / 2)
        hcenter = int(height / 2)
    
        for i in range(hcenter):
            print('-' * (wcenter - 3 * i - 1) + ".|." * (2 * i + 1) + '-' * (wcenter - 3 * i - 1))
            
        print('-' * (wcenter - 3) + "WELCOME" + '-' * (wcenter - 3))
        
        for i in range(hcenter - 1, -1, -1):
            print('-' * (wcenter - 3 * i - 1) + ".|." * (2 * i + 1) + '-' * (wcenter - 3 * i - 1))
    
  • + 0 comments

    Solution for Designer Door Mat Problem

    Problem

    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

    1. 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.
    2. Middle Row:

      • Simply print WELCOME centered with dashes.
    3. Bottom Half:

      • Mirror the top half.
      • Motif count decreases as (2 * ((n-1) - height) + 1).
    4. Symmetry Guarantee:

      • 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 STDOUT
    n, m = map(int, input().split())
    
    dash = '-'
    center = '.|.'
    welcome = 'WELCOME'
    
    dash_mul_top = 3 * (n // 2)
    dash_mul_bottom = 3
    
    for height in range(0, n):
        if height < n // 2:
            # Top half
            print(dash * dash_mul_top, end="")
            print(center * (2 * height + 1), end="")
            print(dash * dash_mul_top, end="")
            dash_mul_top -= 3
            print()
    
        elif height == n // 2:
            # Middle row
            dash_mul_middle = (m - len(welcome)) // 2
            print(dash * dash_mul_middle, end="")
            print(welcome, end="")
            print(dash * dash_mul_middle, end="")
            print()
    
        else:
            # Bottom half
            print(dash * dash_mul_bottom, end="")
            print(center * (2 * ((n - 1) - height) + 1), end="")
            print(dash * dash_mul_bottom, end="")
            dash_mul_bottom += 3
            print()
    

    Example

    Input:

    7 21
    

    Output:

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

    Complexity Analysis

    • Time Complexity:

      • We print exactly n lines, and each line is of length m.
      • Complexity = O(n * m) (printing dominates).
    • Space Complexity:

      • Only a few counters and string multiplications are used.
      • No extra storage proportional to n or m.
      • Complexity = O(1) auxiliary space.

    ✅ The solution is clean, efficient, and guaranteed to run within constraints.

  • + 0 comments
    n,m = map(int,input().split())
    top_bottom_loop = (n - 1) // 2
    # top layer
    dot_pattern = 1
    for i in range(top_bottom_loop):
        hyphen = (m - 3 * dot_pattern) // 2
        print('-' * hyphen + ".|." * dot_pattern + '-' * hyphen)
        dot_pattern += 2
    
    # mid layer
    hyphen_welcome = (m - 7) // 2
    print("-" * hyphen_welcome + "WELCOME" + "-" * hyphen_welcome)
    
    # bottom layer
    dot_pattern -= 2 
    for i in range(top_bottom_loop):
        hyphen = (m - 3 * dot_pattern) // 2
        print('-' * hyphen + ".|." * dot_pattern + '-' * hyphen)
        dot_pattern -= 2
    
  • + 0 comments

    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,'-'))

  • + 0 comments

    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