Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Mock Test  plrn4pf@gmail.

com

Full Name: Renat Yurkevich

Email: plrn4pf@gmail.com
100% scored in Mock Test in 40 min
Test Name: Mock Test on 25 Mar 2024 22:09:55 IST
195/195
Taken On: 25 Mar 2024 22:09:55 IST

Time Taken: 40 min/ 40 min

Invited by: Ankush

Invited on: 25 Mar 2024 22:09:45 IST

Skills Score:

Tags Score: Algorithms 195/195


Constructive Algorithms 90/90

Core CS 195/195

Easy 105/105
Greedy Algorithms 90/90

Medium 90/90
Problem Solving 195/195

Search 105/105

Sorting 105/105
problem-solving 195/195

Recruiter/Team Comments:

No Comments.

Question Description Time Taken Score Status

Q1 Find the Median  Coding 2 min 49 sec 105/ 105 


Q2 Flipping the Matrix  Coding 37 min 3 sec 90/ 90 

QUESTION 1 Find the Median 



Coding Sorting Search Algorithms Easy problem-solving Core CS

Problem Solving
Correct Answer

QUESTION DESCRIPTION
Score 105

The median of a list of numbers is essentially its middle element after sorting. The same number of
elements occur after it as before. Given a list of numbers with an odd number of elements, find the median?

Example

1/5
The sorted array . The middle element and the median is .

Function Description

Complete the findMedian function in the editor below.

findMedian has the following parameter(s):


int arr[n]: an unsorted array of integers

Returns
int: the median of the array
Input Format

The first line contains the integer , the size of .


The second line contains space-separated integers

Constraints

is odd

Sample Input 0

7
0 1 2 4 6 5 3

Sample Output 0

Explanation 0

The sorted . It's middle element is at .

CANDIDATE ANSWER

Language used: JavaScript (Node.js)

1
2 /*
3 * Complete the 'findMedian' function below.
4 *
5 * The function is expected to return an INTEGER.
6 * The function accepts INTEGER_ARRAY arr as parameter.
7 */
8
9 function findMedian(arr) {
10 var sortedArr = arr.sort((a,b) => a-b)
11
12 return sortedArr[(sortedArr.length-1)/2]
13
14 }
15

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 1 Easy Sample case  Success 0 0.0351 sec 42.6 KB

Testcase 2 Easy Hidden case  Success 35 0.0386 sec 43.8 KB

Testcase 3 Easy Hidden case  Success 35 0.0462 sec 45 KB

2/5
Testcase 4 Easy Hidden case  Success 35 0.0846 sec 56.3 KB
estcase asy dde case  Success 35 0 08 6 sec 56 3

No Comments

QUESTION 2 Flipping the Matrix 



Coding Algorithms Medium Greedy Algorithms Constructive Algorithms

problem-solving Core CS Problem Solving


Correct Answer

QUESTION DESCRIPTION
Score 90

Sean invented a game involving a matrix where each cell of the matrix contains an integer. He
can reverse any of its rows or columns any number of times. The goal of the game is to maximize the sum
of the elements in the submatrix located in the upper-left quadrant of the matrix.

Given the initial configurations for matrices, help Sean reverse the rows and columns of each matrix in the
best possible way so that the sum of the elements in the matrix's upper-left quadrant is maximal.

Example

1 2
3 4

It is and we want to maximize the top left quadrant, a matrix. Reverse row :

1 2
4 3

And now reverse column :

4 2
1 3

The maximal sum is .

Function Description

Complete the flippingMatrix function in the editor below.

flippingMatrix has the following parameters:


- int matrix[2n][2n]: a 2-dimensional array of integers

Returns
- int: the maximum sum possible.

Input Format

The first line contains an integer , the number of queries.

The next sets of lines are in the following format:


The first line of each query contains an integer, .
Each of the next lines contains space-separated integers in row of the
matrix.

Constraints

, where .

Sample Input

3/5
STDIN Function
----- --------
1 q = 1
2 n = 2
112 42 83 119 matrix = [[112, 42, 83, 119], [56, 125, 56, 49], \
56 125 56 49 [15, 78, 101, 43], [62, 98, 114, 108]]
15 78 101 43
62 98 114 108

Sample Output

414

Explanation

Start out with the following matrix:

Perform the following operations to maximize the sum of the submatrix in the upper-left quadrant:
2. Reverse column ( ), resulting in the matrix:

3. Reverse row ( ), resulting in the matrix:

The sum of values in the submatrix in the upper-left quadrant is


.

CANDIDATE ANSWER

Language used: JavaScript (Node.js)

1
2 /*
3 * Complete the 'flippingMatrix' function below.
4 *
5 * The function is expected to return an INTEGER.
6 * The function accepts 2D_INTEGER_ARRAY matrix as parameter.
7 */
8
9 function flippingMatrix(matrix) {
10 var sum =0
11 for(let i=0; i< matrix.length/2;i++){
12 for(let j = 0; j< matrix[0].length/2;j++)
13 sum+= Math.max(matrix[i][j], matrix[i][matrix[0].length-j-1],matrix[
14 matrix.length- i-1][j],matrix[ matrix.length- i-1][matrix[0].length-j-1])
15 }

4/5
16
17 return sum
18
19 }

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 1 Easy Sample case  Success 0 0.0355 sec 42.6 KB

Testcase 2 Easy Hidden case  Success 15 0.0996 sec 54.5 KB

Testcase 3 Easy Hidden case  Success 15 0.118 sec 56 KB

Testcase 4 Easy Hidden case  Success 15 0.0809 sec 53.4 KB

Testcase 5 Easy Hidden case  Success 15 0.0927 sec 54.7 KB

Testcase 6 Easy Hidden case  Success 15 0.1265 sec 55.6 KB

Testcase 7 Easy Hidden case  Success 15 0.119 sec 57.6 KB

Testcase 8 Easy Sample case  Success 0 0.0361 sec 42.6 KB

No Comments

PDF generated at: 25 Mar 2024 17:21:38 UTC

5/5

You might also like