Question: Goldman Sachs Quant OA | Matrix Multiplication | Matrix Inversion | OLS Solution | 26th July 2023
1
Entering edit mode

Question 1

Matrix Multiplication

You are given a NxN matrix.Your task is to write a function to return the inverse of the matrix 

Input Format

  • The first line contains a positive integerN indicating number of rows of the matrix .
  • The second line contains a positive integer N indicating number of columns of the matrix 
  • Each of the next N lines contains N space separated numbers denoting a row of the first matrix.
  • Round all the elements of the result matrix to the nearest integer

Constraints:

  • N<=100
  • Assume the input matrix is invertible. 
  • Usage of any external packages which are not already imported will lead to the invalidation of the solution provided

Output Format

Output N lines, the inverse of the matrix.
 

Sample Input

2 
2 
0.3  0.4 
-1 1



Question 2

Matrix Multiplication

You are given two matrices of any dimensions. Your task is to return the product of these matrices.

Input Format

The first line contains a positive integerM1 indicating number of rows of the first matrix.

The second line contains a positive integerN1 indicating number of columns of the first matrix.

Each of the next M1 lines contains N1 space separated numbers denoting a row of the first matrix.

The next line contains a positive integer M2 indicating number of rows of the second matrix.

The second next line contains a positive integer N2 indicating number of columns of the second matrix. 

Each of the next M2 lines contains N2 space separated numbers denoting a row of the second matrix.

Round all the elements of the resultant matrix to the nearest integer.

Constraints:

M1,N1, M2, N2<=100

Usage of any external packages which are not already imported will lead to the invalidation of the solution provided.



Question 3

OLS Solution

Given two 1D arrays of same length(X = independent; Y-dependent), the ordinary least square (OLS) solution are a set of variables(alpha and beta) such that the squared error between Y and (alpha + beta*X) is minimized.

Using Matrix Multiplication and Matrix Inversion or otherwise, get the OLS solution of a given problem with input as 1D arrays of X and Y. 1

 The OLS Solution has to be returned in the format of a 1D array containing alpha and beta in that order. 

Input Format

  • The first line contains a positive integer N indicating number of entries for X
  • Each of the next N lines contains the entries of X
  • The first line contains a positive integer N indicating number of entries for Y
  • Each of the next N lines contains the entries of Y
  • Round alpha and beta to the nearest integer.

Constraints:

  • N<=1000
  • Usage of any external packages which are not already imported will lead to the invalidation of the solution provided.
  •  

 

 

ADD COMMENTlink 17 months ago PoGo 2.4k

Login before adding your answer.

Similar Posts
Loading Similar Posts