HackerRank Python Solution - Strings - Designer Door Mat

Mr. Vincent works in a doormat manufacturing company. One day, he designed a new doormat with the following specifications:
  • Mat size must be N x M. (N is an odd natural number, and M is 3 times N.)
  • The design should have 'WELCOME' written in the center.
  • The design pattern should only use |,. and - characters.
Sample Designs:

HackerRank Python Solution - Strings - Designer Door Mat

Input Format:
  • A single line containing the space-separated values of N and M.
Constraints:
  • 5 < N < 101
  • 15 < M < 303
Output Format:
  • Output the design pattern.
Sample Input:

9 27
Sample Output:

HackerRank Python Solution - Strings - Designer Door Mat

Solution:

# Enter your code here. Read input from STDIN. Print output to STDOUT

n,m= map(int,input().split())
center = n//2
count = -1
for i in range(0,n):
    
    if i == center:
        count += 2
        pattern = 'WELCOME'
        print(pattern.center(m,'-'))
        
    elif i < center:
        count += 2
        pattern = '.|.' * count
        print(pattern.center(m,'-'))
    
    elif i > center:
        count -= 2
        pattern = '.|.' * count
        print(pattern.center(m,'-'))

Disclaimer:
 The problem statement is given by hackerrank.com but the solution is generated by the Geek4Tutorial admin. If there is any concern regarding this post or website, please contact us using the contact form. Thank you!

No comments:

Post a Comment

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...