Showing posts with label Algorithm. Show all posts
Showing posts with label Algorithm. Show all posts

Friday, February 11, 2011

Puzzle: Help Jim

Lora and Jim agreed to play a number game, Lora comes up with a statement that “for any two prime numbers greater than 6 and whose difference is 2, the number between those two prime numbers is always divisible by 6”. How can Jim prove it?

Tuesday, May 18, 2010

Longest substring 0's & 1's

Given a string containing 0's and 1's. One would need to find the longest sub-string such that the count of 0's is equal to the count of 1's in the largest sub string.

0 1 0 1 0 0 0 1 0 1 0 1 0
            |<------->|
              |<------->|

Here solution is either 0 1 0 1 0 1 or 1 0 1 0 1 0.

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.

Tuesday, September 22, 2009

Find a fast solution

I came across this problem recently and found it interesting.

Say you got an input array and output array of equal length. The input array has random integers and you need to populate the output array by following this criteria.

The element at index i of the output array will the product of all the elements in the input array, excluding the element at position i.

ie output[k] = Product of i's { i=0..n-1, where i≠k }

Write a code/algo that will work the FASTEST.

cross posted at basicsuncovered.