Pergunta de entrevista da empresa Yahoo

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

Respostas da entrevista

Sigiloso

28 de nov. de 2010

use run-length encoding.

Sigiloso

23 de fev. de 2011

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

Sigiloso

26 de fev. de 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.

Sigiloso

30 de out. de 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.