Goldman Sachs Technology Online Assessment
Dups make me Crazy
In a production system, we receive lot of data and in some cases data contains duplicates. In order to process the data correctly, we need to identify the rows which contains duplicates.
In this problem, you are receiving data in 2D array (m * n) format and you need to find the number of rows containing duplicate data based on the below criteria.
Operation 1:
Returns the number of rows containing duplicate data in rows (minimum count of duplicates can vary)
See Test case 1 and 2 in below example
Operation 2:
Returns the number of rows wherever there are duplicates in the columns across rows (minimum count of duplicates to consider the row can vary)
See Test case 3 and 4 in below example
If none of the above operation then program will return -1.
Input
1 3 5 9
1 2 1 2
1 4 7 9
1 5 9 11
20 25 20 35
Test Case 1
Input Format with explaination
5 -> Number of Rows
4 -> Number of Columns
1 3 5 9 -> Row Data
1 2 1 2 -> Row Data
3 5 9 11 -> Row Data
20 25 20 35 -> Row Data
1 -> Operation
1 -> Minimum count of duplicates
Output Format
2
Explanation: Here 1 and 2 and repeated in second row and 20 is repeated in last row. Since the minimum count of duplicate is 1, both the rows are eligible.
Test Case 2
Input Format with explaination
5
4
1 3 5 9
1 2 1 2
3 5 9 11
20 25 20 35
1
2
Output Format
1
Explanation: Here 1 and 2 and repeated in second row and 20 is repeated in last row. Since the minimum count of duplicate is 1, only second row is eligible.
Test Case 3
Input Format with explaination
5
4
1 3 5 9
1 2 1 2
3 5 9 11
20 25 20 35
2
1
Output Format
3
Explanation: Here 1 is repeated in the first column (selecting first 3 rows) and 9 is repeated in last column (selecting first and third row). Since the minimum count of duplicates to consider the row is 1, selecting all 3 rows
Test Case 4
Input Format with explaination
5
4
1 3 5 9
1 2 1 2
3 5 9 11
20 25 20 35
2
2
Output Format
2
Explanation: Here 1 is repeated in the first column (selecting first 3 rows) and 9 is repeated in last column (selecting first and third row). Since the minimum count of duplicates to consider the row is 2, we selected first and third row resulting in 2 rows (in both the rows duplicates exist in first and last column)
Solution
***Coming Soon***
No comments :
Post a Comment