Question : Let A be an array of integers of size 100. This array consists of numbers 0-99 randomly distributed over it. Write an algorithm / Propose a method to sort the array ?
...
...
...
...
Answer : Since the numbers are from 0-99, Simply go through the array and replace the first element with 0, the second with 1, ..so on.. replace the last one with 99..
It just requires some common sense.. and the question can be twisted .. instead of array we could have the linked list.. instead of 0-99 we could have numbers 1,4,9,16....so on..
1 comment:
:)... nice one. Will get quite some people smiling at simplicity
Post a Comment