Showing posts with label interview programming challenge tough problems. Show all posts
Showing posts with label interview programming challenge tough problems. Show all posts

Monday, May 26, 2008

Interview programming challenge 5#

This post gives you answer for the question posted at

http://www.dev102.com/2008/05/26/a-programming-job-interview-challenge-5-records-sorting/

You are asked to sort a collection of records. The records are stored in a file on the disk, and the size of the file is much bigger than available memory you can work with. Assume a record size is 10 bytes and file size is 1GB. you read and write data to/from disk in units of pages where each page is 1KB big. You have few (less than 10) available pages of physical memory. Assume you are given a method to compare two records.

How can you sort the records under the described conditions?

* Hint - Using the virtual memory is not the correct answer.


The appropriate solution for this problem would be to use algorithm based on Insertion Sort



Interview programming challenge 4#

This current post give the solution for a problem given in the following URL,

http://www.dev102.com/2008/05/19/a-programming-job-interview-challenge-4/

How would you implement the following method: Foo(7) = 17 and Foo(17) = 7. Any other input to that method is not defined so you can return anything you want. Just follow those rules:

  • Conditional statements (if, switch, …) are not allowed.
  • Usage of containers (hash tables, arrays, …) are not allowed.
The solution for this question would be as following, the following code is written in java

public int Foo(int x){
return 22^x;
}