5 kyu
Two arrays -- Zero rows and zero columns
117myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
Given two 2D integer array arr1
and arr2
. They have the same numbers of rows and columns. For example:
arr1 = [[1, 3,-5], arr2 = [[-1,-3, 5],
[2,-4, 6]] [-2,-4,-6]]
Then plus two integers of the same position of two array. We can got a new array:
[[0, 0, 0],
[0,-8, 0]]
Your task is to count the number of zero rows and zero columns(all elements are zero in a row or column).
In the example above, the result is 3(row 0, column 0, and column 2).
Note:
- Arguments
arr1
andarr2
always be valid inputs; - Please pay attention to optimizing the code to avoid time out.
- In the performance test(5000x5000 elements x2 x 100 testcases), the time consuming of each test case should be within 6ms. This means, Your need a faster algorithm, your code should run as fast as a rocket ;-)
Some Examples
arr1=[
[1, 1],
[1, 1]]
arr2=[
[-1,-1],
[10, 9]]
countZeroRowsAndColumns(arr1,arr2) === 1
arr1=[
[1, 2, 3],
[4, 5, 6]]
arr2=[
[-1, -2, -3],
[-4, -5, -6]]
countZeroRowsAndColumns(arr1,arr2) === 5
Algorithms
Puzzles
Similar Kata:
Stats:
Created | Dec 4, 2016 |
Published | Dec 4, 2016 |
Warriors Trained | 414 |
Total Skips | 4 |
Total Code Submissions | 1432 |
Total Times Completed | 117 |
JavaScript Completions | 117 |
Total Stars | 25 |
% of votes with a positive feedback rating | 86% of 44 |
Total "Very Satisfied" Votes | 33 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 6 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |