Wednesday, September 22, 2010
Joseph problem
There are n persons numbered from 0 to n - 1 standing in a circle. The person number k, counting from the person number 0, is executed. After that the person number k of the remaining persons is executed, counting from the person after the last executed one. The process continues until only one person is left. This person is a survivor. The problem is, given n and k detect the survivor's number in the original circle.
In-place_matrix_transposition
How to do in-place matrix transposition?.
Note, if it is n*n matrix, then we can just do one traversal and swap [i][j] with [j][i].
But what if it is not square matrix?.
Note, if it is n*n matrix, then we can just do one traversal and swap [i][j] with [j][i].
But what if it is not square matrix?.
Find subarray which has equal number of 1s and 0s
How to find subarray from a array of 0s and 1s such that subarray should have equal number of 1s and 0s.
For eg:
11100 --> 1100
00111 ---> 0011
For eg:
11100 --> 1100
00111 ---> 0011
Find number in rotated sorted array.
How to search for a given number in a sorted array which are circularly rotated by few times.
Find three numbers in array which occur only once.
Given an array of n integers, such that each number in the array appears exactly twice, except for three numbers (say a, b and c) which appear exactly once. In O(n) time and O(1) space find a,b and c.
Find next larger number
Given: a number containing N decimal digits (N can be very large), represented as a string. Problem: find the permutation of this string that represents the first number that is bigger than the given one, or return null if such number does not exist. Example: 279,134,399,742 -> 279,134,423,799
Post office problem
How to place P post-offices in a city of N houses such that if every house wants to post a letter on a day then the overall distance traveled is minimum.
Consider city has 2d , each house is represented by a point, and we need to find P points such that sum of diff of P points and N points should be minimal.
Consider city has 2d , each house is represented by a point, and we need to find P points such that sum of diff of P points and N points should be minimal.
Subscribe to:
Posts (Atom)