We need to construct BST not binary tree.
On Sun, Mar 3, 2013 at 6:19 PM, Krishnan aariyankrish...@gmail.com wrote:
Example: when we have nodes 1,2,3. The Minimum weight is given by, 2-root
1-left 3-right (Min. Weight - 10) or 3-root 2-left 1-left(left of 2)
(Min. Weight -10).
On Sun,
Given a set of numbers, we have to construct a tree such that their WEIGHT
is MINIMUM. WEIGHT(node value * height of the node).
(Root is at the height 1).
we need to print the minimum weight.
How to approach this problem ?
Pls somebody help
--
You received this message because you are
No, it is only O(n), but space will be order of O(maximum element in the
range)
Because only one loop to go through all the intervals and get the maximum.
Then allocate space for that much, after that again go through intervals
and increment the corresponding value.
Then after that finding
you can have this code for better understanding
#includestdio.h
long long v[50];
long long a[50];
inline long long getvalue( int index, int low, int high)
{
return a[index] + (high-low+1)*v[index];
}
long long update( long long index, long long down, long long up, long long
Hello All,
I need to know about amazon online test, has anyone given that?
How many and what type of questions they ask? Time period anything?
Thanking you
*Cheers
Raghav Garg
--
+91-9013201944*
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
My wife plays a 3d shanghi variant which has an annoying feature,
that sometimes the game becomes blocked and has to reshuffle which
is a totally computerish solution to keep the game going.
It works like this; the game pieces are little cubes which are arranged
in a bigger cube (or other 3d
First sort the intervals
So, in our example it will be as follows
(2,7),(5,10),(6,15).
make a map which has got interval with corresponding number of overlaps
Now, iterate through each of the interval
for(i=0;i(n-1);i++)
for(j=0;jn;j++)
update the map with the number of overlaps.
@immars , can you explain with some example or algorithm ?
Thanks
Shashank
On Tuesday, February 5, 2013 9:14:03 AM UTC+5:30, immars wrote:
suppose:
v : array of guards' request
P(n): our problem: least coin spent until guard n, according to these rules
M(n, x): least coin possibly
Hi Shubham,
This may be because your final data type you have chosen for your output
is float, n the one which you are trying to print is of int data type (i.e. %d).
Suggestion : Try changing %d to %f and see whether it works for you or not?
Thanks Regards,
Pratts
On 01-Mar-2013, at 1:11,
In the SPOJ , for the given test case, output should be 4 right?
The problem is to find the maximum number of overlapping intervals right?
If you look at the example it should be 4 rigth?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
Hi Danh , shouldn't be C will farthest leaf node from given A and B ?
Thanks
Shashank
On Sunday, January 13, 2013 7:43:23 AM UTC+5:30, Danh Nguyen wrote:
Hi everyone,
I'm trying to solve this problem, but I have no idea to
beginhttp://discuss.codechef.com/questions/5069/tree-again#.
I
The output of the below code is also zero ,
key reason is floating point number are stored as *mantissa, exponent. *
float dec=1.00;
printf(\n dec=%d , float =%f,dec,dec);
On Fri, Mar 1, 2013 at 12:05 PM, Karthikeyan V.B kartmu...@gmail.comwrote:
O/p will not be 0.
1.00 is the result
take two stacks of O(logn) space use one to traverse as left - root-
right (inorder) and other as right-root- left(reverse inorder) like
while (true){
a=top(s1);
b=top(s2);
if(a+b==sum ) break;
if(a+b sum){
pop(s1);
}else if(a+b sum) pop(s2);
}
if(s1 s2 are empty) no solution
else result
Q) why super class object can't be implicitly converted to subclass? is
there any specific reason?
Thanks in advance!
--
sulekha metta
B.E computer science
osmania university
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To unsubscribe
Example: when we have nodes 1,2,3. The Minimum weight is given by, 2-root
1-left 3-right (Min. Weight - 10) or 3-root 2-left 1-left(left of 2)
(Min. Weight -10).
On Sun, Mar 3, 2013 at 5:46 PM, Krishnan aariyankrish...@gmail.com wrote:
Given a set of numbers, we have to construct a tree such
lines = 0;
string last_n_lines[n];
//read each line into a circular buffer
while(getline(file,last_n_lines[lines%n]))
{
lines++;
}
// if number of lines n
// then print all of them
if(lines=n)
{
start = 0;
count = lines;
}
else
{
start = lines%n;
count = lines;
}
//Now print all of
Read line by line . use doublylinkedlist(Queue)/ Circular Buffer of size N.
when EOF is achieved print the lines.
On Mon, Mar 4, 2013 at 9:10 AM, Ashish Goel ashg...@gmail.com wrote:
Q1. Given a log file, pirnt last n lines. Note that the Log file is being
written into.
Q2. Implement
I think DP soln would be :
int leastPay(int[] demands, int sum, int index) {
if(index == demands.length)
return sum;
else {
if(sum demands[index])
return leastPay(demands, sum+demands[index], index+1);
else
return
Ans to *Boundary traversal of a tree. Write the code.
*1) you need to for preoder oder for left most tree with flag and post
order traversal for right most tree with flag.
2) the role of flag would be to decide wther to print or not like in case
of left subtree ,flag would be tree as u knw that
We all know that the order of a permutation is the Least Common Multiples
of its disjoint cycles' lengths. Also, we know that an involution is a
permutation whose order is at most 2. The number of involutions of length n
can be obtained from this recurrence relation: F[n] = F[n - 1] + (n - 1)
i have few questions regarding ur problems pratik :
1) A tree with only parent pointer, how to find LCA?
Doubt : do u mean only root of the tree is given , i am assuming root along
with two nodes address whose lca need to
find too is given , i am right ?
2) Find top k searched elements
some thing like would work.
int find(int x ) {
int p = sqrt(x/2);
int total=0;
float y;
for( int i=0;i=p;i++) {
y=sqrt(x*x-i*i);
if( y(int) == y) total++;
}
return total;
}
find(
}
On Thu, Feb 14, 2013 at 10:22 AM, Shachindra A C sachindr...@gmail.comwrote:
Guneesh,
Thanks for the
i think what aditya suggested is cool but in that instead of going for
largest element we need to search smallest value and its index would he
number we are looking for.
On Sun, Feb 24, 2013 at 7:45 PM, Dave dave_and_da...@juno.com wrote:
@Marti: If you know m and k, and if m is even and k is
Conver your BST to a doubly linked list by doing an inorder traversal. Now
do the normal find sum procedure
Sorry but i have no idea about normal tree case.
On Tue, Mar 5, 2013 at 9:08 PM, Dave dave_and_da...@juno.com wrote:
@Marti: I'm not quite sure if you mean that there are two problems,
Hi all ,
if an array is given in random order , you have to output the minimum
number of swaps required to convert into cyclic sorted array.
e.g. array given is 3 5 4 2 1
so the first swap will be 5--4 result : 3 4 5 2 1
second swap will be 2--1 result : 3 4 5 1 2 (final)
output : 2
i think its just a logical reason take animal as superclass bird as
subclass ... since we are talking about inheritance it is is a
relationship ie bird is a animal not vice versa hence we cannot
implicitly convert to subclass
On Sat, Mar 2, 2013 at 6:18 PM, sulekha metta
didn't understand your question please specify the question with an example.
On Sat, Mar 2, 2013 at 6:18 PM, sulekha metta metta.sule...@gmail.comwrote:
Q) why super class object can't be implicitly converted to subclass? is
there any specific reason?
Thanks in advance!
--
sulekha metta
what ever data members,member functions present in super class are
applicable to subclass...subclass may contain more additional
featuresso its obvious that size of subclass object is more than
superclass object...now lets take an analogy of float(4 bytes) and double(
8 bytes) float can be
these questions were asked for software dev. in amazon ? which round .
looks like straight easy questions...
On Sun, Mar 10, 2013 at 5:58 PM, Nishant Pandey
nishant.bits.me...@gmail.com wrote:
Ans to *Boundary traversal of a tree. Write the code.
*1) you need to for preoder oder for left
Hi Shashank,
It could be. But if the tree has only 2 branches, and A, B lie as two leaf
nodes on each branch, there won't be any more leaf position for C. Thus, C
has to lie on the path between A and B. Could you give me some hint to find
C in O(lgN) though?
On Mon, Mar 4, 2013 at 3:19 PM,
according to my understanding the super class object have limited function
like for example
Class - animal : methods/behavior : roam() and eat()
and a sub class hippo : method/behavior : roam(),eat() and swim()
so a hippo is a animal then according to the polymorphic property of java
a reference
31 matches
Mail list logo