you give 0indexed m x n binary matrix matrix integer numSelect denote number distinct column select matrixlet consider s c1 c2 cnumselect set column select a row row cover s iffor cell matrixrowcol 0 col n 1 matrixrowcol 1 col present s orno cell row value 1you need choose numselect column number row cover maximizedreturn maximum number row cover set numselect column example 1input matrix 000101011001 numselect 2output 3explanation one possible way cover 3 row show diagram aboveWe choose s 0 2 row 0 cover occurrence 1 row 1 cover column value 1 ie 0 2 present s row 2 cover matrix21 1 1 present s row 3 cover matrix22 1 2 present sThus cover rowsnote s 1 2 cover 3 row show row coveredexample 2input matrix 10 numSelect 1output 2explanation Selecting column result row cover entire matrix selectedTherefore return 2 Constraintsm matrixlengthn matrixilength1 m n 12matrixij 0 11 numselect n