Sort by

recency

|

597 Discussions

|

  • + 0 comments
    import re
    
    # Read input dimensions
    n, m = map(int, input().split())
    
    # Read the matrix
    matrix = [input() for _ in range(n)]
    
    # Transpose the matrix to read column-wise
    decoded = ''.join([''.join(row) for row in zip(*matrix)])
    
    # Replace non-alphanumeric characters between two alphanumeric ones with a space
    result = re.sub(r'(?<=[a-zA-Z0-9])[^a-zA-Z0-9]+(?=[a-zA-Z0-9])', ' ', decoded)
    
    # Print the final result
    print(result)
    
  • + 0 comments

    print(re.sub(r'(\w)\W+(\w)', r'\1 \2', ''.join(map(lambda x: ''.join(x), zip(*matrix))))

  • + 0 comments

    import re

    Step 1: Input dimensions

    n, m = map(int, input().split())

    Step 2: Read the matrix

    matrix = [input() for _ in range(n)]

    Step 3: Transpose the matrix and build the decoded string

    decoded = ''.join([matrix[i][j] for j in range(m) for i in range(n)])

    Step 4: Use regex to replace symbols/spaces between alphanumerics with space

    print(re.sub(r'(?<=[A-Za-z0-9])[^A-Za-z0-9]+(?=[A-Za-z0-9])', ' ', decoded))

  • + 1 comment

    Can someone explain to me why `#!/bin/python3 import re

    first_multiple_input = input().rstrip().split()

    n = int(first_multiple_input[0])

    m = int(first_multiple_input[1])

    matrix = [0] * (n * m)

    for x in range(n): matrix_item = input() for y in range(m): matrix[y * n + x] = matrix_item[y]

    decoded_matrix = re.sub(r'(?<=[A-Za-z\s])!@#%&', ' ', ''.join(matrix)) decoded_matrix = re.sub(r'(?<=[\w])\s{2,}(?=[\w])', ' ', decoded_matrix) print(decoded_matrix)

    Is only 81% correct? It runs, passed all test cases, and locally only takes ~.03 seconds on the test cases.

  • + 0 comments

    Here is HackerRank Matrix Script in Python solution - https://programmingoneonone.com/hackerrank-matrix-script-problem-solution-in-python.html