Coding Exercise

cubeEarlier this week I was talking with a colleague about sites that are becoming quite popular with software developers (e.g., HackerRank https://www.hackerrank.com). The format is quite similar between sites. A problem is described. You need to write correct code to solve it.

All have a window in which you can write the necessary code. Most of the constraints for the problem are described. The better sites provide some sample data sets to test your solution.

After you are satisfied with the code, you submit it. The software gets checked using additional tests and you get back your score.

The problem that we were discussing follows:

Provided a random set of integers within the range 0 < n <= N, one should be able to respond to the following questions for each n:

  • If the number has been already presented (duplicate).
  • If the number is in a range of consecutive numbers.

N: [1, 1000]

For example; given the following random sequence of integers, the proper responses follow:

n Response
2 None
4 None
1 In sequence [1,2]
7 None
9 None
4 Duplicate
3 In sequence [1,4]
8 In sequence [7,9]

I will write an additional set of four blog entries with the following approaches:

Language Solution
C Queues no data structure.
C Queue with data structure.
Java Queues no data structure.
Java Queue with data structure.

If you have comments or questions please let me know.

Happy hacking;

John

Leave a Reply

Your email address will not be published. Required fields are marked *