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
--
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
--
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:
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.
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
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
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
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
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.
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
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
// 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
12 matches
Mail list logo