Amazon Interview Question
Software Engineer / Developers<number of zeros> <number of non-zeros> abc ... <number of zeros> etc.
For example:
abc000defg00
becomes
0 3 abc 3 4 defg 2
That works. It can be improved as
abc000defg00
abc02defg00
What's done above is that only in cases of number of zeros exceeding 2 in number, the encoding will have 0n else 0 or 00 if the no. of zeros are 2 or 1 in number. The use of extra character for delimiter is not required as the 0 itself will denote the start of the series of zeroes.
000uuwe00000000ii0adsf000
02uuwe07ii0adsf02
i guess one thing we could do is....... insert a special character followed by the number of Zero's whenever you encounter a series of zero's in the file ......... if you encounter the special character in the file indent the file with another copy of the special character .... thus while reproducing the original file print only one special character when you encounter 2 special characters
eg:
000abc34340000@sfo@6500
here we are using '@' as the special character to identify the number of zero's
output:
@3abc3434@4@@sfo@@65@2
you can just store the number of zero's right..why do you want sparse matrix?
- Messi September 09, 2010