[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 spac

[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 inpu

[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

[algogeeks] Re: Triangle war problem - C++

2013-08-02 Thread igor.b...@gmail.com
Start at this one: http://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning -IB On Friday, August 2, 2013 1:56:14 AM UTC-4, Naren s wrote: > > > Can anyone help me solve this problem. > > http://poj.org/problem?id=1085 > > > -- > Regards, > *Narayanan S* > > -- You received this message becaus

Re: [algogeeks] Find the max element of sets of size K

2013-09-19 Thread igor.b...@gmail.com
Hey, isn't it as simple as: 1. Start at sum of the first K elements. 2. Move the "window" of size K by one element to the right at each step. Subtract the left, add the right => get the new sum. Keep the maximum. This executes in O(n) steps, requires O(1) memory. The code in C++ seems to be tr