Saturday, November 24, 2012

Programming Interview Questions - 14



Q1. Given a calendar of events, design an algorithm to find all the overlapping events.


Q2. Given a sorted array of numbers containing duplicates, find the last occurrence of a given number.


Q3. Write a function which outputs itself.

Hint: Quine computing


Q4. Given two numbers x and y having equal number of digits, rearrange x such that x is greater than y and difference d = (x-y) is the least among all the x's possible by its rearrangement.
Example: x = 1234
               y = 2410
Rearranged x is 2413


Q5.  We have given a matrix A[m][n] where each cell is either 0 or 1. Adjacent cells ( top, bottom, left, and right ) having similar value (1 or 0) are considered connected. An island is a set of connected cells. Design an algorithm to count the numbers of the dis-connected islands.