HackerRank Matrix Script problem solution in python YASH PAL, 31 July 2024 In the Matrix script problem, Neo has a complex matrix script. The matrix script is a N X M grid of strings. It consists of alphanumeric characters, spaces, and symbols (! @,#,$,%,&). Print the decoded matrix script. Problem solution in Python 2 programming. # Enter your code here. Read input from STDIN. Print output to STDOUT import re N, M = (int(x) for x in raw_input().split()) ain = [] tin = [] for i in range(N): ain.append(raw_input()) for i in range(M): for j in range(N): tin.append(ain[j][i]) print re.compile(r"([a-zA-Z0-9])[^a-zA-Z0-9]+([a-zA-Z0-9])").sub(r"1 2", "".join(tin)) Problem solution in Python 3 programming. #!/bin/python3 import math import os import random import re import sys first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) m = int(first_multiple_input[1]) matrix = [] for _ in range(n): matrix_item = input() matrix.append(matrix_item) encoded_string = "".join([matrix[j][i] for i in range(m) for j in range(n)]) pat = r'(?<=[a-zA-Z0-9])[^a-zA-Z0-9]+(?=[a-zA-Z0-9])' print(re.sub(pat,' ',encoded_string)) Problem solution in pypy programming. # Enter your code here. Read input from STDIN. Print output to STDOUT import re n, m = map(int, raw_input().split()) arr = ''.join([''.join(t) for t in zip(*[raw_input() for _ in xrange(n)])]) print re.sub(r'b[^a-zA-Z0-9]+b', r' ', arr) Problem solution in pypy3 programming. # Enter your code here. Read input from STDIN. Print output to STDOUT import re n,m =map(int,(input().split())) a,b = [],"" for _ in range(n): a.append(input()) for z in zip(*a): b +="".join(z) print(re.sub(r"(?<=w)([^w]+)(?=w)"," ",b)) coding problems python