@ rahul sharma:
the linked list is a combination of a list a-b-...-p-q and a cycle
q-r-...-z-q. (z != p).
noting that the start of cycle q is the only node with 2 predecessor: p
and z.
if 2 pointers meet at some node x, different from q, in last step they
must have met at x', the predecessor
, rspr wrote:
@Terence: The DP approach is nice.
if we have constraint likewhile choosing the first 3 edges if it
makes a triangle so we will require n edges to connect the graph
completely...in the same fashion...after selecting 2 more
edgesagain we have to check that is it making more
Here is an DP solution:
(consider only simple graph, with at most 1 line between any 2 distinct
points, and no point connect to itself)
Suppose f(n,m) is the number of ways m lines can connect n points.
Then f(n,m) = 0 when m n-1 or m n(n-1)/2;
For graph with n vertices and m edges
1. the computing of d is incorrect.
d = n-1;
while((d1)==0) d=1;
2. the accuracy of pow is far from enough. you should implement your own
pow-modulo-n method.
3. for big n, (exceed 32bit), x=(x*x)%n can be overflow also. you may
need to implement your own multiply method in this
;
}
main()
{for(int k=1;k20;k++) printf(%d is %d\n,k,is_prime(k)); getch();}
On 1/18/12, Sourabh Singhsinghsourab...@gmail.com wrote:
@ sunny agrawal
you are right. but i have used check an also . no improvement .
i think algo is wrong in later part.. somewhere..
@ Terence
1) pow may not work
error in pow.
as long as n 2^31, x*x fits into int64_t, since xn.
On 2012-1-18 20:51, Sourabh Singh wrote:
@ Terence
I belive nw its giving wrong answer for n41 onwards
due to error's in pow and x*x over flow as u already stated...
i guess algo is right nw.. ;-)
thanx again..
On 1/18/12
%n for each
then multiply to get result..
but my question is what if power is prime and big...
On 1/18/12, Terencetechnic@gmail.com wrote:
error in pow.
as long as n 2^31, x*x fits into int64_t, since xn.
On 2012-1-18 20:51, Sourabh Singh wrote:
@ Terence
I belive nw its giving wrong
and popped out.
If we could not find an unmatched close bracket, and the stack is not
empty,
we examine the stack and return the bottom index (the left most unmatched),
or the top index (the inner most unmatch) as needed.
On 2011-12-22 13:27, Terence wrote:
Then what's your output for test case
Then what's your output for test case ()(()?
On 2011-12-22 12:45, atul anand wrote:
i guess there is no need of stack , we can take a variable say top;
increment top when open bracket occur ( and decrement when close
bracket ) occurs.
keep track of first close bracket mismatch i.e when top
http://en.wikipedia.org/wiki/Binary_heap#Building_a_heap
The algorithm of heap-building presented in most books is O(n).
On 2011-9-16 12:52, Ankuj Gupta wrote:
is talks of more tighter bound of O(nlogn)
On Sep 15, 11:24 pm, sunny agrawalsunny816.i...@gmail.com wrote:
Read CLRS
On Thu,
P^2/QR+Q^2/PR+R^2/PQ
= (P^3+Q^3+R^3)/PQR
= ((P+Q+R)(P^2+Q^2+R^2-PQ-QR-PR)+3PQR)/PQR
= 3
On 2011-9-15 13:29, rahul sharma wrote:
hw?
On Thu, Sep 15, 2011 at 10:57 AM, Tamanna Afroze afroze...@gmail.com
mailto:afroze...@gmail.com wrote:
yah the ans is 3
--
You received
CONT1D and D1ONE already defined
When compile with -O2, gcc 4.3.2 tries to inline short functions like
gcd(). Thus the labels CONT1D and D1ONE get redefined.
1) Try gcc 4.0.3.
or 2) use local labels instead. eg.
__asm__ __volatile__ ( movl %1, %%eax;
0: cmpl
Traversal the suffix tree is enough.
All substrings from root to leaf (including at least 1 character of leaf
node) occur only once.
Choose the shortest among them.
On 2011-6-15 5:28, T3rminal wrote:
@bittu
How can u find the shortest substring from the tree in 0(n). Can u
please elaborate a
a,b,c,d,e,f do not need to be distinct.
(It is possible that a=b=c=d=e=f, see Example 1)
On 2011-6-10 12:01, saurabh singh wrote:
Problem link- ABCDEF https://www.spoj.pl/problems/ABCDEF/
Can someone please explain this problem.The problem says a,b,c,d,e,f
belongs to S.But what if size of S
84 years.
The well known Diophantus Riddle:
http://en.wikipedia.org/wiki/Diophantus#Biography
On 2011-6-7 16:03, Lavesh Rawat wrote:
***Salman age puzzle
*
**
***
***
**
***salman's youth lasted one sixth of his life. He grew a beard after
one twelfth
Try this case:
1000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1
On 2011-5-18 0:27, Kunal Patil wrote:
Ohh..If it is so...Sorry !! I understood it the different way...
But if the question is as mentioned in your 2nd case then also I
believe there is O(n) solution.
Guard value error.
L[n1]=;
R[n2]=999;
R[n2] may be merged and counted, if L[1..n1-1] has 999.
On 2011-5-12 19:18, Akshata Sharma wrote:
I tried to solve this problem using merge sort logic, the algorithm is
same as merge sort, only change is in the merge step where i am
@Manikanta: What compiler do you use?
$ gcc test.c
test.c:2: error: initializer element is not constant
$ g++ test.c
$ ./a.out
Hello
$ gcc --version
gcc (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the
In this problem, sum can be as large as 5*10^9.
Try breaking the whole interval into several stages (no more than 2*N),
each with a fixed amount of tasks.
Then in each stage, the schedule is a simple loop: A B C D E A B C D E A
B ...
Process each stage in O(1) time, then the total time
4 * 4 - 7 = 9
Start both sandglasses at the same time. When the 4-minute sandglass is
over, flip it to restart timing. Repeat this 3 times.
From the moment when the 7-minute sandglass is over, to the moment when
the 4-minute sandglass is over for the 4th time, is an interval of 9
minutes.
On
I will get the gold coin or nothing.
On 2011-3-7 16:11, Lavesh Rawat wrote:
***Get Gold Coin **Problem Solution*
*
*Imagine there are 3 coins on the table: gold, silver, and copper. If
you make a truthful statement, you will get one coin. If you make a
false statement, you will get nothing.
system(yes Hello);
(on Linux)
On 2011-3-7 2:09, sudheer kumar wrote:
use GOTO
On Sun, Mar 6, 2011 at 10:49 PM, UMESH KUMAR kumar.umesh...@gmail.com
mailto:kumar.umesh...@gmail.com wrote:
How to print Hello Infinite times without using
Loop and Recursion function ?
--
You
On 2011-3-2 6:22, rgap wrote:
Hi, does anybody know when/where to use
typedef long long int64;
When 64-bit integer is needed.
and
const long double EPS = 1E-9;
When dealing with floating number comparison.
--
You received this message because you are subscribed to the Google Groups
SeeTen-Hat Variant
(http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle#Ten-Hat_Solution).
On 2011-3-3 18:02, rajul jain wrote:
@naveen
but in this question don't know numbers of black and red hats like
prison and hat puzzle
On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar
@Dave: I think it is to find the longest substring which appears more
than once in the given string.
@bittu:
You could use suffix tree: http://en.wikipedia.org/wiki/Suffix_tree, and
find the deepest branch node.
or use suffix array: http://en.wikipedia.org/wiki/Suffix_array, and find
the
Then it should be:
struct UserData
{
uType m_dataType;
union {
int m_intValue;
float m_floatValue;
char m_charValue;
};
} data;
On 2011-2-22 15:29, Rajiv Podar wrote:
Hi Shiva,
There is no as such way to know what type of value is stored in the
Nope.
The union defines an memory region of 4 bytes (on 32-bit OS).
Access age/grade only specifies which part is retrieved / modified.
You may assign value to age, then retrieve grade, or vice versa.
On 2011-2-22 14:45, shiva wrote:
I have an union with following members
union data
{
int age;
Variable start and hex_buf point to string constant, which can not be
modified.
Change:
char *start = 12.12.12.12.12976665176069214;
char *hex_buf = 65003a0a;
to:
char start[] = 12.12.12.12.12976665176069214;
char hex_buf[] = 65003a0a;
On 2011-2-15 15:01, dinesh bansal
Try scanf/printf instead of cin/cout.
For huge data set, the IO time matters.
On 2011-2-14 20:09, Akshata Sharma wrote:
link to problem: http://www.spoj.pl/problems/MAJOR/
On Feb 14, 5:03 pm, Akshata Sharmaakshatasharm...@gmail.com wrote:
I am trying to submit my solution but its giving TLE.
No. It can be applied to any positive number N.
The solution above splits the numbers by the least significant bit,
choose the group with missing number, and then drop the last bit and
continue.
In this way the set [0,N] is partitioned (almost) evenly into 2 groups:
{2k | k=0,1,...,N/2} and
No need for calculating individual magic(x), just count the number of
ordered list L with max(L)=11.
Partition those ordered list by its gcd, and check each part, then you
can see the trick.
On 2011-1-13 11:06, Pratik Bhadkoliya wrote:
For example,
for 1: divisor is only 1
No BFS, only mathematics.
Get the better one out of the 2 choices.
(Maybe simulating each of the 2 choices also fits into the time limit,
given the input range in the problem page.).
On 2011-1-12 9:28, Bharath 2009503507 CSE wrote:
i tried solving this prob...
node , return 0 if the leaf has the value needed else
return INFINITY.Also if at any internal node if it is not possible
return INFINITY.
On Tue, Dec 28, 2010 at 10:06 AM, Anand anandut2...@gmail.com
mailto:anandut2...@gmail.com wrote:
@Terence.
Could please elaborate your answer
return INFINITY.
On Tue, Dec 28, 2010 at 10:06 AM, Anandanandut2...@gmail.com wrote:
@Terence.
Could please elaborate your answer. Bottom up level order traversal helps
to get the final root value but how to use it to find minimum flips needed
to Obtain the desired root value.
On Fri, Dec 24, 2010
' be the index of the
minimum element(x[h] is minimum)
Then, dp[i][j]=v+sigma(f!=h)[min(x[f],y[f])]
The other cases are similar to this!
I can write a code and send if you have doubts.
On Dec 28, 9:36 am, Anandanandut2...@gmail.com wrote:
@Terence.
Could please elaborate your answer. Bottom up level
when you are talking abt starting from 1 that means that array is 1
based , right ?
Right.
111
000
000
Up-left element: 1
Choice 3: 0 (number of 0's on the first row) + 1 (number of 1's on the
first column) = 1
Choice 4: 3 (number of 1's on the first row) + 2 (number of 0's on the
first
Using the same level order traversal (bottom up), calculating the
minimum flips to turn each internal node to given value (0/1).
On 2010-12-24 17:19, bittu wrote:
Boolean tree problem:
Each leaf node has a boolean value associated with it, 1 or 0. In
addition, each interior node has either
My method is using DP, as Snehal have pointed out.
Suppose S[0..n-1] and T[0..n-1] denotes the score and time for the n
questions respectively.
C[k][s] denotes the maximum total time when choosing from the first k
questions such that the total score do not exceed s.
Then C[0][s] = 0
@Ankur:
It is just 0/1 knapsack problem:
Choose a subset of the questions with sum of scores not exceeding
(Total Score - Pass Score), while maximize the sum of time of the subset.
So I do not think O(nlogn) greedy algorithm will solve this problem.
On 2010-12-23 23:38, Ankur Khurana
@Saurabh:
You are right. I was supposed there were infinite 0's on the left.
For 32-bit number, the MSB should also be checked in addition to LSB.
Change the first line to: c=1-(N1)-((N31)1); will fix this case.
On 2010-12-22 14:44, Saurabh Koar wrote:
@Terence: I think the above fails
I second Bhavesh.
If A knows B, then B is not a spy; else A is not a spy.
Thus we can hold an elimination races:
for each pair A,B in a match, ask if A knows B, and eliminate as
above.
In total N-1 matches are needed to decide the final winner.
If there is a spy, then the spy is the
zero_group(N) {
c=1-(N1); // For even N, zero groups is one more than 1 groups.
while(N) {
d = (N(-N)); // Get the least significiant bit.
N = N+d; // Clear the last 1-group bits
c++; // inc counter.
}
return c;
}
For more bit manipulations, refer to
I think nobody dies on the first 19 days and everyone dies on the 20th day.
(I have no difference with other green-eyes. Why I have to suicide
ealier? : )
Given: a) there was at least one green-eyed among them,
we could get the following conclusions:
1) If there is exactly 1 green-eye, he
Just the opposite.
All the operands are evaluated from left to right, and the right most
operand is returned as the value of whole comma expression.
But remember the operator precedence. Comma is lower than assignment.
So c=--a, b++ - c is equivalent to c=--a; b++ -c;
While c=(--a, b++ -c) is
Here is an O(N^2) algorithm:
1. Sort both A and B. (O(NlogN) or O(N^2), either will work)
2. For each element C[k] in C, find if there is such (i,j) pair that
A[i] + B[j] = -C[k]:
Start with i = 0 and j = N-1, and loop through the following:
a. if A[i] + B[j] -C[k], then j = j-1;
I think the answer is (2^m)^(2^n) (or 2^(m*2^n))
For m=1, the answer is 2^2^n.
We can express the function using a truth table with 2^n entries, one
entry for each possible input set.
And each entry has (n+m) fields, represent the n inputs and m outputs.
The m*2^n output fields can be filled
No. You made the same mistake as I.
Try this case: {1, 2, 2, 5, 5}.
Actually, this case defeats the solution of Manmeet's, yours, and mine.
(same min/max, same sum, same xor result)
I think the key point is that the N variable cannot be determined by 1
or 2 equation constraint.
On 2010-12-10
As Amir pointed out:
convert the first row and first column to all zeros
In details:
1. choose operations on first row and first column to make up-left
element 0.
* There are 2 cases, 2 choices for each case:
1. If the up-left element is 0, then
Good point. Here is one step further:
3. Consider the center 4 numbers(regardless of order): {1,8,a,b},
containing 2 even and 2 odd.
and {a,b} can be chosen from {3,4,5,6}. Then there is only one case:
{1,8,3,6}.
The rest is trivial.
On 2010-11-12 13:26, Amod wrote:
Let me try to
(((x 0x)1) | ((x 0x)1))
5 bit operations in total.
On 2010-11-12 16:12, sudhir mishra wrote:
Write a program to swap odd and even bits in an unsigned integer with
as few instructions as possible (e.g., bit 0 and bit 1 are swapped,
bit 2 and bit 3 are swapped, etc).
No. It is possible.
This problem focuses on comparisons of each element.
The overall time complexity of merge operation can be as high as O(nlogn),
while the normal merge operation has time complexity O(n).
But the normal merge operation does not meet the requirement, since in
the worst case,
http://www.informatik.uni-ulm.de/acm/Locals/2007/output/
On 2010-10-21 18:59, ANUJ KUMAR wrote:
please give me its output file also so that i can check mine
On 10/21/10, ANUJ KUMARkumar.anuj...@gmail.com wrote:
thanks
On 10/21/10, juver++avpostni...@gmail.com wrote:
Please have a look at
Here is the modified code. Maybe we can find something new.
Code:
#includestdio.h
int main()
{
union {
struct {
int x;
float t;
};
double u;
} a;
a.x=0;
scanf(%f,a.t);
printf(%f\n,a.t);
printf(%f\n,a.u);
a.x=90;
printf(%d\n,a.x);
printf(%f\n,a.x);
On 2010-10-8 15:14, snehal jain wrote:
A Double Tower of Hanoi contains 2n disks of n different sizes, two of
each size. As usual, we’re required to move only one disk at a time,
without putting a larger one over a smaller one.
a. How many moves does it take to transfer a double tower from one
order of all disks is preserved after 1)-7).
Denote the number of moves as f(n) in case a), and g(n) in case b).
We have:
f(n) = 2^(n+1) - 2 and
g(n) = 4f(n-1)+3.
So g(n) = 4*2^n-5
On 2010-10-9 1:56, ravindra patel wrote:
@Terence
Solution for first one is trivial. Just double the number
If +,-,*,/ is completely forbidden, I think at least one loop is needed.
Here is my solution:
int next8mult (int n)
{
n = (n ~7);// clear the least 3 bit to make
multiple of 8
int r = 8;
while(r) { // add 8 to n
int r1 = (nr) 1; // get
It is true that there are infinitely many solutions (or zero
solutions) (x, y, z) in any case.
But what we are interested here is S=x+y+z.
Apply y = S-x-z, you get:
S/Vp+x(1/Vd-1/Vp)+z/(1/Vu-1/Vp) = T1
S/Vp+x(1/Vu-1/Vp)+z/(1/Vd-1/Vp) = T2
Adding the two, you get
2S/Vp +
You could also get a unique solution if the car has speed of 72 63 56
in downhill, plain and uphill respectively.
I think the speed Vd, Vp, Vu was chosen so that 2Vp = Vd + Vu.
But for unique solution, it ought to be 2/Vp = 1/Vd + 1/Vu.
Under this condition, we can get the unique S=x+y+z:
it will take 3 hrs to climb while travelling from B to A and plain
road distance = 5/3 * 64 = 106.67 km
dist = 168 + 106.67
On Wed, Sep 15, 2010 at 8:21 AM, Terence technic@gmail.com
mailto:technic@gmail.com wrote:
You could also get a unique solution if the car has speed of 72 63 56
The following algorithm traversals both lists twice to find the
intersection point, without modification to the original nodes.
The only assumptions:
1) Head pointer of two list: La, Lb
2) .next point to the next node.
3) .next of the tail node is NULL
intersect(La,Lb)
{
// Find the length
No coding at all.
1) Take out another A pill from the bottle;
2) Split each of the 4 pills into two equal halves, and take one half of
echo pill.
3) Collect the other half of the 4 pills for next time.
On 2010-9-14 17:22, bittu wrote:
You are on a strict medical regimen that requires you to
Or directly get the last digits from (-1, 0, 1)
100 = 33 * 3 + 1
33 = 11 * 3 + 0
11 = 4 * 3 + (-1)
4 = 1 * 3 + 1
1 = 0 * 3 + 1
Collect those digits together, we get 11X01_3
On 2010-8-31 23:40, Dave wrote:
352/9 = 39-1/9
= 27 + 9 + 3 + 1/9
= 1*3^3 + 1*3^2 + 1*3^1 + 0*3^0 +
Simple run-length encoding of a ascii picture.
On 2010-9-1 3:49, Albert wrote:
#includestdio.h
main()
{
int a,b,c;
int count = 1;
for (b=c=10;a=- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
at 10:36 PM, Yan Wang wangyanadam1...@gmail.com
mailto:wangyanadam1...@gmail.com wrote:
It's miracle can you explain?
On Sun, Aug 29, 2010 at 8:07 PM, Terence technic@gmail.com
mailto:technic@gmail.com wrote:
Try this:
int main()
{
int data = (int
First convert 352.
352 = 117 * 3 + 1
= (39 * 3 + 0) * 3 + 1
= ((13 * 3 + 0) * 3 + 0) * 3 + 1
= (((4 * 3 + 1) * 3 + 0) * 3 + 0) * 3 + 1
= 1*3+1) * 3 + 1) * 3 + 0) * 3 + 0) * 3 + 1
So 352 = 111001.
Noting 9 = 3^2, thus 352 / 9 = 1110.01
On 2010-8-31 7:46, Raj N
No need to handle -1 specially.
6)
-2 |-1| 1
| 1|
Binary : 11
On 2010-8-30 20:37, ANKIT AGGARWAL wrote:
divide each number by -2 until you get -1, or 1 (Remembering that
remainder is always +ve)
Ex
1)
-2 | 2 | 0
| -1 |
Interpret -1 as 11
so binary is 110
2)
-2 | 3 | 1
On 2010-8-25 20:25, Terence wrote:
1. Calculate the length of both list (A, B).
2. Find the position in the longer list corresponding to the head of
shorter list, and copy the previous digits to output list C.
(Or for simplicity, appending 0 to the shorter list so as to get
the same
.
else, keep all those digits untouched.
Advance px to x' and x to the next of x'.
5. Remove the initial 0s until C begins with non-zero digits.
On 2010-8-25 23:45, Raj N wrote:
@Terence: It is subtraction of 2 lists and not addition. N for your
logic of addition for x9 you add
1. Calculate the length of both list (A, B).
2. Find the position in the longer list corresponding to the head of
shorter list, and copy the previous digits to output list C.
(Or for simplicity, appending 0 to the shorter list so as to get the
same length as the longer one)
3. Add the two
I think count sort is not acceptable (see Ankur's post for
explanation), while radix sort fits the requirement.
Take the array as an array of 2-digit base n numbers.
First sort by the least significant digit (x%n), then the most
significant digit (x//n), both using the stable counting sort.
On 2010-7-26 1:46, Tech Id wrote:
int cond (int x, int y, int z) {
return (x==0)*z + (x!=0)*y;
}
Or
int cond (int x, int y, int z) {
return (!x) * z + (!!x)*y;
}
if comparing (==/!=) is not permitted.
On Jul 21, 10:29 pm, BALARUKESHsbalarukesh1...@gmail.com wrote:
Ternary
Don't try to simulate the scheduler on every second. The total execution
time can reach 5 * 10^9 sec.
Play with small examples, get the task list in execution order, and
find the cyclic property of the list.
You can solve this problem in O(N) time complexity.
On 2010-6-20 18:15, Shravan
vertical_traversal(v)
{
stack_init(vstack);
stack_init(tstack);
while(v)
stack_push(vstack, v);
if(v.right)
stack_push(tstack, v.right);
v = v.left;
while(! is_empty(vstack))
visit(stack_pop(vstack));
while(! is_empty(tstack))
No need to enumerate all possible states.
In the final state (2,8,5), each jug is neither full nor empty, while
every valid operation has to fill or empty one jug.
So it is not possible to get this state from any other state by one
valid operation. (As others said, the state before the final
On 2010-6-11 13:39, BALARUKESH wrote:
The increment and decrement method wont work correctly for all
cases
Ex:-
))a+b((
It works. In this example, the first ')' lead to -1 which indicate the
expression is not well formed.
This is not a well formed parenthesis... But satisfies the
You can restore the infix expression from the postfix expression
calculated, only add parenthesis when necessary in each step.
On 2010-6-3 15:35, divya jain wrote:
1.calculte the postfix of given expression.
2.now remove a particular parenthesis from expression and check if the
postfix of
Discard illegal prefix as soon as possible, and only proceed with legal one.
* For some position, if the number of '(' and ')' are equal, then do not
try ')' on that position.
* If the number of '(' reaches n, fill the rest positions with ')' to
get a valid permutation.
On 2010-6-3 16:15,
This is a different problem, where the requested number with maximum
frequency is not necessary majority.
On 2010-6-1 13:19, harit agarwal wrote:
see this .vote majority algorithm..
http://userweb.cs.utexas.edu/~moore/best-ideas/mjrty/index.html
The simplest case is:
A A
/ and \
BB
both with preorder(and level-order) AB and postorder BA
On 2010-4-9 1:23, Himanshu Aggarwal wrote:
For a binary tree , if we are given an inorder traversal and a
preorder/postorder/level-order
Suppose n=2^k, a(0), a(1), ..., a(n-1) are the n teams
1. If there are 1 team, then no matches, 0 days needed;
If there are 2 teams, arrange 1 match for them, 1day needed.
2. Split the n teams into 2 groups of equal size, ie.
a(0),a(1),...,a(n/2-1) and a(n/2),a(n/2+1),...,a(n-1).
3.
What is the storage structure of your BST?
If each node contains pointers to its left child, right child and
parent, then we can traverse through the tree without recursive or stack.
in_order_traverse()
{
p = root;
last = root-parent = NULL;
while(p) {
if (last == p-parent) { //
No. This works for all cases. Xor is commutative.
On 2010-2-5 13:37, srinivas chintagunta wrote:
I think this works if elements are sorted . Is it correct?
On Mon, Feb 1, 2010 at 5:07 PM, sachin sachin_mi...@yahoo.co.in
mailto:sachin_mi...@yahoo.co.in wrote:
A way to solve this problem
On 2010-1-28 21:03, Nirmal wrote:
Given two binary search trees, how to merge them in O(n) time and O(1)
space?
It can be done using O(n) space as below,
1. covert BST #1 into linked list or sorted array
2. covert BST #2 into linked list or sorted array
3. merge them...
but how to do this in
The problem can break down to simple case A:
A. convert a row of size c elements to all zero using only operations a, b
which can further break down to substep B:
B. for any two different value x, y in a row, use only operations a, b
to convert to same value.
Suppose x = y, perform operation a
84 matches
Mail list logo