Given the matrix a, return the index r of the row with the most nonzero elements. Assume there will always be exactly one row that matches this criterion.
Example:
Input a = [ 1 2 0 0 0 0 0 5 0 0 2 7 0 0 0 0 6 9 3 3 ] Output r is 4
How am I wrong here?
"a = [ ...
1 0 0;
0 0 0;
0 0 0;
0 0 0;
0 2 3];
r_correct = 5;"
My code says 2, I think it's correct, what am I missing?
It wants the number of the row with the most nonzeros.
Thank you Tim! I feel like a fool, but that'll teach me to read the requirements more carefully. Hopefully.
Great Problem!
nice
Love this one
Piece of cake
nice
easy :) but nice
there is a bug i the code
input a = [1 0 1 1 ; 9999 0 0 0]
output 2
there is a bug in the code
input a = [1 0 1 1 ; 9999 0 0 0]
output 2
r = max(sum((a==0)'));
Original solution I created by digging through documentation was x=a~=0; y=sum(x,2); [M,I]=max(y); r=max(y). Solution had a size of 31 so I compressed it into it's current version.
in case number 3 and 4 total number of element is also less than your correct fullest row output
How does this thing is possible
I did it!
(^^;)
this is a terrible solution, someone help.
Could you tell me how you did it?
Once again ive used a for loop only because it seems so much simpler. The more I do these I see how each person has a different approach to a problem which I think is very cool. Thanks for the problem!
test suite is not ok
what is the problem here ? it works on matlab and gives the correct row
2 things: You forgot to set your output (so add a line r=ix, or change the r in the first line into ix.
and you changed the function name so it doesn't recognize it.
Your solution does work.
Well done.
Is there any way to avoid this for loop??
Yes, a hint: compare with zeros matrix and count (sum) the nonzero elements in this logical matrix.
Can you please tell how did you do this with the size of 10?
Just again the regexp Cheat, I guess!
I can't believe, that this is still working... Why don't they ban all the Cheating possibilities?
It's completely unfair, to all other players!
The regexp cheat kind of shadows the "normal" solutions.
can you show that '10'?
I did not mean to like this, but the 'Unlike' button does not work!
looks very strange
I can't believe I used a trick I learned from Javascript...
I tried to optimize my solution as much possible as I could, still my code size was 45, any idea what would be there in the leading solution of this problem which has code size as 11 ? Which trick did you use?
511 Solvers
Basics: 'Find the eigenvalues of given matrix
237 Solvers
Determine the number of odd integers in a vector
298 Solvers
236 Solvers
308 Solvers