Pregunta de entrevista de Yahoo

Design a data structure to store sparse 2D matrix which contains only 0 or 1. then write function to add 2 such matrix.

Respuestas de entrevistas

Anónimo

28 nov 2010

use run-length encoding.

Anónimo

23 feb 2011

store each row as a decimal for ex: if the row is 1011 -> store it as 13!

Anónimo

26 feb 2011

Since all values are mod 2 you can pack 64 entries together into on int64_t. You can then add two matrices by XORing each entry.

Anónimo

30 oct 2010

I first proposed to use array to remember each 1 location. then find out it is quite expensive to do the addition. with the interviewer's help, I result in using hash table. then I was asked to write hash function. It was quite challenge for me. But the interviewer was really nice and very helpful to push me to the limit.