Replace NaNs with the number that appears to its left in the row.
If there are more than one consecutive NaNs, they should all be replaced by the first non-NaN value to the immediate left of the left-most NaN. If the NaN is in the first column, default to zero.
For example, if
x = [NaN 1 2 NaN NaN 17 3 -4 NaN]
then
y = [ 0 1 2 2 2 17 3 -4 -4]
The problem does not limit the array to a single row. Add a few cases of multiple rows or define as single row.
Not really a solution, more like a "white flag" regarding this direction.
hint: recursion
big size ...!
I just realized that you can cause inconvenience to some players by posting cody problems like "Hello Everyone!!!". I did create that cody problem just to say Hi to my fellow cody players. It was not intended to waste your time or cause inconvenience. My apologies for whoever deleted that problem.
I am sure it was deleted by mistake, there are plenty of similar Cody problems (think Chuck Norris, indian mathematicians, smartest matlab programmers, and a long etc...) Perhaps Ned can put it back up?
Thanks for the reply sir.
Strange...those assertions pass on my computer
For the second test it gives: [0 0 1 2 2 2 17 3 -4] instead of [0 1 2 2 2 17 3 -4 -4]
Nice, it is very intuitive that a solution with this function is possible but still hard to find.
It's like a lesson. logical indices don't have to be full size! And for will apparently loop through a vector! Thanks!
Bonus! Vector doesn't have to be monotonic!
2518 Solvers
Make a random, non-repeating vector.
1122 Solvers
190 Solvers
315 Solvers
198 Solvers