[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Puzzle: Zero rows and columns in an array in C#

[Puzzle: Zero rows and columns in an array in C#]

This puzzle is given as a coding example in the book Cracking the Coding Interview by Gayle Laakmann McDowell. The puzzle is:

Write an algorithm such that if an element in an M x N matrix is 0, its entire row and column are set to 0.

In other words, given an array, if an entry is 0, set all of the entries for its row and column to 0. A few rules:

  • Make sure the program is correct. Don't get carried away and fill the whole array with 0s.
  • Be efficient. Don't use more time or extra space than necessary.
  • Don't use tools that are specific to the .NET Framework or C#. For example, Array.Copy, MemCopy, RtlMoveMemory, and other tools can help you copy an array quickly. Don't use any of those.

I'll post the book's solution (converted from Java into C#) and my solution next week.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.