[algogeeks] Amazon problem

2013-06-11 Thread Jai Shri Ram
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region . For example, X X X X X O O X X X O X X O X X After running your function, the board should be: X X X X X X X X X X X X X O X X --

[algogeeks] Intrestting problem

2013-06-11 Thread Jai Shri Ram
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region . For example, X X X X X O O X X X O X X O X X After running your function, the board should be: X X X X X X X X X X X X X O X X --

Re: [algogeeks] Re: Median of two sorted arrays of different sizes

2013-06-11 Thread Abhirup Ghosh
How is this code dealing with the scenario where two arrays have common number. For example where two arrays are same. A[] = {1,2,3,4} and B[] = {1,2,3,4}. Here the median position is not (4+4)/2 rather it is 4/2. On Sun, Jun 9, 2013 at 3:12 PM, rahul sharma rahul23111...@gmail.comwrote:

Re: [algogeeks] Re: Max-Overlapping Intervals

2013-06-11 Thread Ritesh Mishra
it is better to use Binary Index Tree ( Fenwick Tree) with time complexity O(log n) to update and O(n * log n) for finding max overlapping interval . http://community.topcoder.com/tc?module=Staticd1=tutorialsd2=binaryIndexedTrees this link can be useful for understanding how it will work.

[algogeeks] Re: Max-Overlapping Intervals

2013-06-11 Thread igor.b...@gmail.com
Colleagues, how about the following? At each start point, the total number of leaving elephants increases by one; at each end point, it decreases by one. We: 1. form a vector of pairs: {5, +1}, {10, -1}, {6, +1}, {15, -1}, {2, +1}, {7, -1} ... -- this takes O(N) time and O(N) additional

[algogeeks] Re: Max-Overlapping Intervals

2013-06-11 Thread sunny
igor way is the optimized way using prefix sum just a small correction with in life period of (l,r) you have to do v[l]++, v[r+1]--(v is initialized to zero ) take a prefix sum of v and return the max value containing index On Thursday, February 21, 2013 3:10:17 PM UTC+5:30, NITHIN HOTKER

[algogeeks] Re: Max-Overlapping Intervals

2013-06-11 Thread sunny
ohh..sorry you have to return interval so give the starting index of prefix sum array to the last index of containing the maximum value of array On Thursday, February 21, 2013 3:10:17 PM UTC+5:30, NITHIN HOTKER wrote: Given life time of different elephants find *period when maximum number

[algogeeks] Re: Google Interview Question: In how many intervals does a number exists

2013-06-11 Thread igor.b...@gmail.com
Monish, please take a look at a similar problem about poor elephants in the neighboring topic started today. I believe the problem has a similar solution. Each start point increases the no. of active intervals by one; each end point decreases it. So, we do the following: 1. Convert the

[algogeeks] Re: Intrestting problem

2013-06-11 Thread igor.b...@gmail.com
How about the following: 1. Think every cell on a board occupied by an O is a vertex in a non-directed graph. Add a special vertex called OuterWorld. 2. Connect all neighboring vertices with edges, based on how you define surrounded by X-es. E.g. in your picture, diagonals are not allowed. 3.

Re: [algogeeks] Re: Google Interview Question: In how many intervals does a number exists

2013-06-11 Thread Avi Dullu
Can you tell the 'size' of your array 'f' if the intervals are [0, 10], [10, 9223372036854775808] ? Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones

[algogeeks] Re: Google Interview Question: In how many intervals does a number exists

2013-06-11 Thread Monish Gupta
Adding to the question. See inline. On Sunday, June 9, 2013 12:50:46 PM UTC+5:30, Monish Gupta wrote: There are n Intervals. *1 = n = 1,000,000.* *Limits of interval are within 64 bit signed int.* Given a set of m numbers, tell in how many intervals does each number exists. Example: 4

[algogeeks] Re: Intrestting problem

2013-06-11 Thread Don
// Flip a region including location (x,y) from from to to. // Returns true if region is surrounded. bool flip(char board[][], int n, int x, int y, char from, char to) { if ((x = 0) (y = 0) (x n) (y n)) return false; if (board[x][y] != from) return true; board[x][y] = to; return