Saturday, May 8, 2010

Array of single & double bytes

@arun_ragh asked me this interesting question.

Given an infinite array containing single and double byte entries in random order. A one bit flag is used to identify if the given entry is single or double byte. If the first bit is set to '1' then its double byte number else if its set to '0' then its a single byte number. Given a pointer to a number somewhere the middle of the array. One needs to find if the previous entry is single or double byte.

Note: There are cases where one would not be able to find out the solution. But assume there exists a possible solution.

4 comments:

Varun said...

My solution -- http://twitpic.com/1m4qi9

Varun said...

The forward traversal can be replaced by a simple math.

Vijesh said...

neat solution

Vijesh said...

But I thought you would have an App in your mobile that you would do a free hand write and get the jpg instead of clicking a paper. :)