Add Border

Add Border

Given a rectangular matrix of characters, add a border of asterisks(*) to it.

Example

For

picture = ["abc",
           "ded"]

the output should be

solution(picture) = ["*****",
                      "*abc*",
                      "*ded*",
                      "*****"]

Input/Output

  • [execution time limit] 4 seconds (py3)
  • [input] array.string pictureA non-empty array of non-empty equal-length strings.Guaranteed constraints:
    1 ≤ picture.length ≤ 100,
    1 ≤ picture[i].length ≤ 100.
  • [output] array.stringThe same matrix of characters, framed with a border of asterisks of width 1.

 

def solution(picture):
    row_count = len(picture)
    column_count = len(picture[0])
    print(row_count)
    print(column_count)
   
    return_picture = []
    temp_aster = “”
    for j in range(0, column_count+2):
        temp_aster += “*”
    return_picture.append(temp_aster)
    for i in range(0, row_count):
        temp_row = “*” + picture[i] + “*”
        return_picture.append(temp_row)
   
    return_picture.append(temp_aster)
    print(return_picture)
    return return_picture
       
   
No Comments

Post A Comment