Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

you can just store the number of zero's right..why do you want sparse matrix?

- Messi September 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<number of zeros> <number of non-zeros> abc ... <number of zeros> etc.
For example:
abc000defg00
becomes
0 3 abc 3 4 defg 2

- lupuslupus September 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Neo September 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think we should also consider the fact that there might me numbers in the file ....

- hacker September 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think we should also consider the fact that there might me numbers in the file ....

- hacker September 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- hacker September 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thats called run-length encoding.

- Anon September 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

There is a more detailed discussion of RLE:

michael.dipperstein.com/rle/index.html

- Anonymous October 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can have more than 10 0's too and you can have that sp. character too in the file. The best way would be to treat 0 as the special character and considering whole 2 to 4 next bytes to store the number of 0's in the integer format.

- yossee October 31, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More