It looks like finding all subsets of a set which satisfy a condition
(sum is ZERO).
Using bit approach
i.e.
01101 == >> 120,150, 316
10100 ==>> -466, 150
int main(int argc, char *argv[])
{
int sum = 0;
int tmp=0;
int i=0;
int a[10]={-466, 120, 150, 421, 316};
int length = 5;
int
Yes, Following should do for next smallest:
1. Find rightmost 01 pair
2. swap these two bits (make it 10)
e.g.
N=3(011), Next smallest: 5(101)
N=10(1010), Next smallest: 12(1100)
N=14(01110), Next Smallest: 22(10110)
On Jan 18, 12:48 am, juver++ wrote:
> @abobe
> my solution is wrong when number
Yes, I guess following correction in step 1 for Next Smallest should
fix it:
1. Find the leftmost 1 [ Not rightmost].
On Jan 18, 12:48 am, juver++ wrote:
> @abobe
> my solution is wrong when number is even (but it can be avoided with some
> corrections into an implementation),
> btw, you have a m
Yes, I guess following correction in step 1 for Next Smallest should
fix it:
1. Find the leftmost 1 [ Not rightmost].
On Jan 18, 12:48 am, juver++ wrote:
> @abobe
> my solution is wrong when number is even (but it can be avoided with some
> corrections into an implementation),
> btw, you have a m
Q1 is very well answered by Sunny but looks like Q2 is still open.
IMHO, juver++ soln on Q2 doesn't look correct to me (OR I didn't
understand the problem).
if given no is N=2 (010), then next smallest no N+1 = 3 (011) is not
the right answer as it has TWO 1's.
I guess, for N=2 (010), next smallest
sort both linked lists using non-recursive merge sort: Time: O(nlogn),
Space: O(1)
Then
while both lists are not null
loop
if list1->data == list2->data then
print/store list1->data
move list1 pointer one node further
move list2 pointer pne node further
else if list1->data < li
That's right. Tks. But looks like above algorithm is for kth smallest.
Not kth largest.
That's why I mentioned inorder traversal as right_child -- >> parent
-- >>
left_child.
Not usual way: left_child -- >> parent -- >>
right_child
On Jan 12, 1:08 am, juver++ wrote:
> If modification of the tree
For 2nd question (probability): Looks like one data is missing for C.
If I assume C can shoot 8 out of 10. times then:
P(A) = 4/5
P(B)=6/7
P(C)=8/10
Required Probability should be = P(A) * P(B) + P(B) * P(C) + P(A) *
P(C)
On Jan 11, 9:58 pm, snehal jain wrote:
> 1. what is valid in cpp
> char *
juver++, If we do inorder traversal (right_child -- >> parent -- >>
left_child) and output kth element then we are done.
I didn't understand the 2nd point, why we need to modify the bst
(store child count at each node).
Am I missing anything here? Please advise.
On Jan 12, 12:04 am, juver++ wrote
juver++, If we do inorder traversal (right_child -- >> parent -- >>
left_child) and output kth element then we are done.
I didn't understand the 2nd point, why we need to modify the bst
(store child count at each node).
Am I missing anything here? Please advise.
On Jan 12, 12:04 am, juver++ wrote
juver++, If we do inorder traversal (right_child -- >> parent -- >>
left_child) and output kth element then we are done.
I didn't understand the 2nd point, why we need to modify the bst
(store clind count at each node).
Am I missing anything here? Please advise.
On Jan 12, 12:04 am, juver++ wrot
juver++, If we do inorder traversal (right_child -- >> parent -- >>
left_child) and output kth element then we are done.
I didn't understand the 2nd point, why we need to modify the bst
(store clind count at each node).
Am I missing anything here? Please advise.
On Jan 12, 12:04 am, juver++ wrot
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b1,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern for all elements while shuffling.
For all elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<= i <= N
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b1,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern for all elements while shuffling.
For all elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<= i <= N
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b1,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern all elements for following while
shuffling.
All elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<=
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b1,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern all elements for following while
shuffling.
All elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<=
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b1,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern all elements for following while
shuffling.
All elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<=
OK. I hope following should do the needful.
Input:
a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN
Output:
a1,b2,a2,b2,a3,b3,a4,b4,..aN,bN.
If we notice, there is a pattern all elements for following while
shuffling.
All elements from 1st half portion (a1 to aN)
a[i] is moved to a[2*i] where 0<=
Hi, I'm new here and looking to learn more on algos and participate in
discussions.
@juver++, Recursion solution to the 1st problem implicitly using
stack. No?
print (list l)
{
if(i->next) print(l->next);
print l;
}
On Jan 6, 4:55 pm, juver++ wrote:
> 1. Recursive function. Print node's
19 matches
Mail list logo