Robot Room Cleaner

Advanced

Robot Room Cleaner

Imagine you have a small cleaning robot at home that works on a grid. The room is represented as an n x m grid where each cell can either be clean (0) or dirty (1). Your task is to help the robot clean the room by counting how many dirty spots there are.

Your mission, should you choose to accept it, is to write a Python function that counts the number of dirty spots the robot needs to clean up.

The function should be called count_dirty_spots and it should take in a 2D list representing the grid of the room. Your function should return the number of dirty spots, i.e., how many 1s are in the grid.

For example:

count_dirty_spots([ [0, 1, 0], [1, 0, 1], [0, 0, 1] ])

This should return 4 because there are four 1s in the grid.

Another example:

count_dirty_spots([ [0, 0], [0, 0] ])

This should return 0 because there are no dirty spots to clean.

Help your robot to become the best cleaner!

Geek
Inputs

Arg 1:

[[0,1,0],[1,0,1],[0,0,1]]
Expected Output
4
Actual Output