InterraIT Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Typically assume that H=1 and T!=H=0 and set the bit accordingly and send this data using the single string.

However you gotto set the protocol on both the points for your assumption.

- hprem991 November 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can we do something like
(H=1, T=0)

Append one extra H (1) at the beginning of the string ..

then convert this into decimal ..

send this number ..
At B: Convert it into binary and discard the first 1, convert all 0 and 1 to T and H ..

Am I doing something wrong here ?

- P November 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here we can use the concept of "Run length coding" along with encoding H and T.
Consider H -> 1
and T -> 0

In a byte allocate 7 bits to represent value upto 2^7 -> 0 - 127
and last 8th bit to represent H(1) , or T(1)
Then apply run length coding.

Hence HHTTTHHHHHTTTTTHTHTTTT can be represented as.

2H3T5H5THTH4T
2H -> 00000101 -> 3
3T -> 00000110 -> 6

similarly for 5H, 5T etc..
Final data sent is byte stream 3,6,.... Etc..
At receiver end , take each bit, consider first 7 bits for number of times the event (H or T ) is repeated, and last bit for the event itself.

This solution give the best performance when repetitions are frequent.

- Anonymous November 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here we can use the concept of "Run length coding" along with encoding H and T.
Consider H -> 1
and T -> 0

In a byte allocate 7 bits to represent value upto 2^7 -> 0 - 127
and last 8th bit to represent H(1) , or T(1)
Then apply run length coding.

Hence HHTTTHHHHHTTTTTHTHTTTT can be represented as.

2H3T5H5THTH4T
2H -> 00000101 -> 3
3T -> 00000110 -> 6

similarly for 5H, 5T etc..
Final data sent is byte stream 3,6,.... Etc..
At receiver end , take each bit, consider first 7 bits for number of times the event (H or T ) is repeated, and last bit for the event itself.

This solution give the best performance when repetitions are frequent.

- Vijay November 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the probability of H and T are same and outcome is independent of the other outputs, then the entropy of the source will be :
=-(.5log(.5) + .5log(.5)) = 1

And according to source coding theorem, we cannot send one outcome not less than entropy of the source which is 1.

Hence it cannot be compressed.

- Anonymous November 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the probability of H and T are same and outcome is independent of the other outputs, then the entropy of the source will be :
=-(.5log(.5) + .5log(.5)) = 1

And according to source coding theorem, we cannot send one outcome not less than entropy of the source which is 1.

Hence it cannot be compressed.

- Anonymous November 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the probability of H and T are same and outcome is independent of the other outputs, then the entropy of the source will be :
=-(.5log(.5) + .5log(.5)) = 1

And according to source coding theorem, we cannot send one outcome not less than entropy of the source which is 1.

Hence it cannot be compressed.

- Rahul Agarwal November 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Send the first outcome as it is. From then on send the number representing how many times it have appeared without change during each switch. So for HHTHHHHHTTTTT...
it would be H|2|1|5| where | represents each switching point.

- CareerCup November 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is a bad solution. If the output is truly random this instead of compressing it will inflate it.

- Anonymous November 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Agreed with anonymous. The thing to realize in this problem is that with very high probability, a random string will be largely incompressible. The best thing is just to encode the data using 1 bit per outcome.

- eugene.yarovoi November 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Or just send bytes representing 8 outcomes at a time. You don't have to use strings. But yes, 1 bit per outcome is the way to transmit it.

- eugene.yarovoi November 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

can be sent as H2TH5T5

- sathishperias November 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

HTHTHTHTHT.....
= H1T1H1T1H1T1......
more data than actual string

- Anonymous November 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Still holds good

if string is hththt then its sent same
but if it has more than 2h or 2t then its numbered
eg
hhthttth
then its sent as hhtht3h

- sathishperias November 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Then why not send it like, 5432, where the number itself says 5 as Heads then 4 tails and 3 heads and then 2 tails again.???

- ishant agarwal November 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It think Its not possible. What it might not start with H but with T. Also what if there are h is 22 times and T is 55 times then it would become intrepretede wrongly . So my solution solves these problems.

- sathishperias November 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

We can use the concept of Run length coding, and enchoding H, and T.
Consider H -> 1
and

- Anonymous November 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

See comments to all solutions similar to this.

- Anonymous November 05, 2011 | Flag


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