Hacker Rank : Reading 2 Dimension matirx

series of input parsing code on hacker rank

by rishul matta

JavaScript

function processData(input) {
    //Enter your code here
    inp = input.split('\n');
    var rows = inp[0].split(' ').map(Number)[0],
        columns = inp[0].split(' ').map(Number)[1],
        rotation = inp[0].split(' ').map(Number)[2],
        matrix;
    
    inp.splice(0,1)
    matrix = inp.map(x => x.split(" ").map(Number))
    console.log(matrix)
} 


processData("4 4 1\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16")



/*
Input Format 
First line contains three space separated integers, M, N and R, where M is the number of rows, N is number of columns in matrix, and R is the number of times the matrix has to be rotated. 
Then M lines follow, where each line contains N space separated positive integers. These M lines represent the matrix.

"4 4 1
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16"
*/