Java Simple Solution using hashset

public class Solution {

public static void setRowZero(ArrayList<ArrayList<Integer>> a, int row){
    
    int n = a.get(0).size();
    for(int j = 0; j < n; j++){
        a.get(row).set(j, 0);
    }
}

public static void setColZero(ArrayList<ArrayList<Integer>> a, int col){
    
    int m = a.size();
    for(int i = 0; i < m; i++){
        a.get(i).set(col, 0);
    }
}

public void setZeroes(ArrayList<ArrayList<Integer>> a) {
    
    int m = a.size();
    int n = a.get(0).size();
    HashSet<Integer> hRow = new HashSet<>();
    HashSet<Integer> hCol = new HashSet<>();
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            if(a.get(i).get(j) == 0){
                hRow.add(i); 
                hCol.add(j);
            }
        }
    }
    
    Iterator<Integer> itrRow = hRow.iterator();  
    Iterator<Integer> itrhCol = hCol.iterator(); 
    
    while(itrRow.hasNext()){  
        setRowZero(a, itrRow.next());
    }
    
    while(itrhCol.hasNext()){  
        setColZero(a, itrhCol.next());
    }
}

}

Click here to start solving coding interview questions