Re: [algogeeks] Re: O(n) Time is the problem. ..

2011-06-24 Thread sunny agrawal
for a naive algorithm. But a little thought can give a divide-and-conquer algorithm which is O(n). Dave On Jun 24, 8:44 am, sunny agrawal sunny816.i...@gmail.com wrote: hmm i also doubt that but it is Strictly O(32n) not O(nlgn) where lgn = 32 depending upon value of n On Fri, Jun

Re: [algogeeks] Re: Sort - Consecutive Array in O(n)

2011-06-24 Thread sunny agrawal
@Adarsh fails on this a[] = {2,2,2,6,6,6} On Sat, Jun 25, 2011 at 10:54 AM, Adarsh s.adars...@gmail.com wrote: int n = A.size(); for (int i=0; in; i++) total += A[i]; findMinMax(A[1...n]); int mean = (max+min)/2; if ((total - n*mean) == 0) printf(consecutive\n); else

Re: [algogeeks] Re: Sort - Consecutive Array in O(n)

2011-06-24 Thread sunny agrawal
@adarsh no it will Fails for both even and odd no of elemets a[] = {2,2,2,4,6,6,6} seems like we need to check for the presence of each no between min to max using a good hashing approach. On Sat, Jun 25, 2011 at 11:20 AM, Adarsh s.adars...@gmail.com wrote: Missed that... also, my method seems

Re: [algogeeks] O(n) Time is the problem. ..

2011-06-23 Thread sunny agrawal
initially compute xor of all the values from 0 to n in a variable Temp so temp = 0^1^2^n let result is used to store the missing number for each ith bit of missing number where i = 0-31 we can find it as following ith bit of result = (xor of all ith bits of values of array) xored with

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS is abcdcba or abcecba not abc or cba On Wed, Jun 22, 2011 at 10:15 PM, ankit mehta mehta.bond...@gmail.comwrote: Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : Both not Palindromes! On Jun 22, 9:29 pm, sanjay ahuja

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS stands for Longest Common Substring -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
ohh sorry my mistake LCS stands for Longest Common Subsequence On Wed, Jun 22, 2011 at 11:21 PM, SVIX saivivekh.swaminat...@gmail.comwrote: ah... i misunderstood the question... sorry.. On Jun 22, 12:01 pm, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest

Re: [algogeeks] Binary Tree

2011-06-22 Thread sunny agrawal
:11 AM, oppilas . jatka.oppimi...@gmail.comwrote: Sunny, Can but can we modify this code to get the *node X and node Y*?. On Wed, Jun 22, 2011 at 8:32 AM, Anantha Krishnan ananthakrishnan@gmail.com wrote: @sunny agrawal *Thanks a lot.* *Great code. I got the logic

Re: [algogeeks] string matching

2011-06-22 Thread sunny agrawal
last line is *in worst case k=1 only 2*n comparisons will be there hence O(n)* On Thu, Jun 23, 2011 at 11:26 AM, sunny agrawal sunny816.i...@gmail.comwrote: Lets Consider the case of Naive matching in which at some shift s first k characters are matched and next character does not match so

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
but it is O(N^2)...will give TLE On Tue, Jun 21, 2011 at 2:33 PM, ross jagadish1...@gmail.com wrote: A small correction, j = 0 to i. On Jun 21, 2:01 pm, ross jagadish1...@gmail.com wrote: Hi, Ya DP with memoization is best.. nCr= n-1Cr-1 + n-1 C r DP]i,j] = DP[i-1,j-1] +

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
DP is good when we need to use intermediate values too.. here we only need to compute nCr as a final result so we cannot use DP here the Logic Vandana used will be helpful here. as nCr = n! / r! * n-r! without loss of generality we can assume that r n-r else we can just replace r = n-r then

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
will increase vry fast and will go out of limit.. - PRAMENDRA RATHI NIT ALLAHABAD On Tue, Jun 21, 2011 at 2:52 PM, sunny agrawal sunny816.i...@gmail.comwrote: DP is good when we need to use intermediate values too.. here we only need

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
this problem is same as *http://www.codechef.com/problems/MARBLES/* solution to this are public u can check for more clarification On Tue, Jun 21, 2011 at 3:51 PM, sunny agrawal sunny816.i...@gmail.comwrote: if it is given tha final answer fits in 64 bit signed integer then we can run a loop

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
i am doing the same thing without using array long long int res = 1; int j = 2; for(int i = n-k+1; i = n; i++){ res *= (long long int)i; while(j = k res%j == 0){ res/=j; j++; } } On Tue, Jun 21, 2011 at 4:25 PM, kartik sachan

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
because j doesn't divide it, it can overflow. On Jun 21, 4:12 pm, sunny agrawal sunny816.i...@gmail.com wrote: i am doing the same thing without using array long long int res = 1; int j = 2; for(int i = n-k+1; i = n; i++){ res *= (long long int)i; while(j = k

Re: [algogeeks] Binary Tree

2011-06-21 Thread sunny agrawal
@Piyush good to start with But i think a recursive O(n) is possible in downward calls pass sum from root to node and on return calls pass sum from leafs to root of each subtree and using this collective information updating a global ans max. On Tue, Jun 21, 2011 at 5:05 PM, Piyush Sinha

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread sunny agrawal
one of the possible create the min heap O(n) keep extracting elements and look for missing elements worst case it will be O(nlgn) equivalent to heap sort or Simply sort using quick sort or merge sort and then traverse through the array and look for missing ones On Tue, Jun 21, 2011 at 7:09 PM,

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
i dont know why r u thinking so but this was my accepted solution for the problem. On Tue, Jun 21, 2011 at 7:34 PM, kartik sachan kartik.sac...@gmail.comwrote: hey sunny suppose u have to calculate 100c50 then there is a lot of chances of over flow becoz u have to multiply 100 to

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
both will work fine in first case in each step what is done is ans = (ans*(n+1-i))/i; what happens is first iteration ans = n, i =1 so i divides ans sec. iteration ans = product of 2 consecutive nos at least one even so divisible by 2 in third, ans is prod of 3 consecutive no.s so divisible by 3

Re: [algogeeks] Binary Tree

2011-06-21 Thread sunny agrawal
see this * https://ideone.com/1ZtIq* On Tue, Jun 21, 2011 at 10:23 PM, Anantha Krishnan ananthakrishnan@gmail.com wrote: Thanks. I expect more details in implementation point of view. Thanks Regards, Anantha Krishnan On Tue, Jun 21, 2011 at 6:41 PM, sunny agrawal sunny816.i

Re: [algogeeks] Coin Chain Reaction

2011-06-20 Thread sunny agrawal
after first Roll no of Expected No of Dices will be 2.5 1/2(0)+1/6(4+5+6) so after second 2.5^2 so after N rounds 2.5^N On Mon, Jun 20, 2011 at 3:56 PM, Navneet Gupta navneetn...@gmail.comwrote: We have an unlimited number of dice at our disposal. Let's roll the die. If the outcome is 1, 2, or

Re: [algogeeks] Coin Chain Reaction

2011-06-20 Thread sunny agrawal
and Expected value should be 2.5^(N-1)*(7/2) -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] Tic Tac Toe

2011-06-17 Thread sunny agrawal
i think u r missing the cases when o is winning and and countx counto then answer should be no On Fri, Jun 17, 2011 at 12:19 PM, KK kunalkapadi...@gmail.com wrote: https://www.spoj.pl/problems/TOE1/ For which test case does this program fail #includeiostream #includevector using

Re: [algogeeks] Re: Tic Tac Toe

2011-06-17 Thread sunny agrawal
no i didn't mean that in first test u checking if count of X should be either equal of one more than that of O and in last u r checking if both are winning or only only one but what i meant is if O has already won but no of moves of X are greater than O the answer should be No but your solution

Re: [algogeeks] Re: Tic Tac Toe

2011-06-17 Thread sunny agrawal
as you can see in this case no of moves of X are 4 and that of O are 3 as X starts first, after both players has played 3 moves each, O would have already won the game so next move of X is invalid i got your solution AC after adding this condition :) On Fri, Jun 17, 2011 at 2:48 PM, KK

Re: [algogeeks] Fiddling with Bits

2011-06-17 Thread sunny agrawal
you need to try something better as limits of A and B are very large :) you can not run a loop from A to B i have not tried it but the logic is there will be many nos which will give the same value and we dont need to calculate for them all explicitply :) On Fri, Jun 17, 2011 at 2:52 PM, KK

Re: [algogeeks] Fiddling with Bits

2011-06-17 Thread sunny agrawal
where n is ?? On Fri, Jun 17, 2011 at 3:23 PM, Arpit Sood soodfi...@gmail.com wrote: i have got AC with O(n) On Fri, Jun 17, 2011 at 2:59 PM, sunny agrawal sunny816.i...@gmail.comwrote: you need to try something better as limits of A and B are very large :) you can not run a loop from

Re: [algogeeks] Fiddling with Bits

2011-06-17 Thread sunny agrawal
but limits of A and B are very large 10^15 how is this possible am i missing something, like Max(B-A) = 10^6 or 10^7 On Fri, Jun 17, 2011 at 3:30 PM, Arpit Sood soodfi...@gmail.com wrote: lol, i mean in linear time On Fri, Jun 17, 2011 at 3:27 PM, sunny agrawal sunny816.i

Re: [algogeeks] Fiddling with Bits

2011-06-17 Thread sunny agrawal
the final result in the order of no of bits O(64) On Fri, Jun 17, 2011 at 3:38 PM, sunny agrawal sunny816.i...@gmail.com wrote: but limits of A and B are very large 10^15 how is this possible am i missing something, like Max(B-A) = 10^6 or 10^7 On Fri, Jun 17, 2011 at 3:30 PM, Arpit Sood

Re: [algogeeks] MS

2011-06-17 Thread sunny agrawal
Try this: say i is the index of the first occurrence of the first character say j is the index of the first occurrence of the second character say n is length of array int Min = n+1; while(i n j n){ int Min = min(Min, abs(i-j)) if(i j){ find next occurrence of first character } else{ find

Re: [algogeeks] [brain teaser ] Number Trick Riddle

2011-06-16 Thread sunny agrawal
n^2 On Thu, Jun 16, 2011 at 12:41 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *Number Trick Riddle - 16 june * * * * *** ** *Sonal asked the class to see if they could find the sum of the first 50 odd numbers. As everyone settled down to their addition, Lavesh ran to her and said, 'The

Re: [algogeeks] Re: find output.

2011-06-16 Thread sunny agrawal
The place where strict constness is not enforced is with character array literals. You can say char* cp = howdy; and the compiler will accept it without complaint. This is technically an error because a character array literal (“howdy” in this case) is created by the compiler as a constant

Re: [algogeeks] Re: find output.

2011-06-16 Thread sunny agrawal
stored at p , and also increments p . On Thu, Jun 16, 2011 at 1:10 PM, sunny agrawal sunny816.i...@gmail.comwrote: The place where strict constness is not enforced is with character array literals. You can say char* cp = howdy; and the compiler will accept it without complaint

Re: [algogeeks] Re: find output.

2011-06-16 Thread sunny agrawal
in such cases for still better understanding :) Be it a book or a website. On Thu, Jun 16, 2011 at 8:13 PM, sunny agrawal sunny816.i...@gmail.comwrote: yes copy pasting the exact thing :) for better understanding :) On Thu, Jun 16, 2011 at 8:06 PM, Navneet Gupta navneetn...@gmail.comwrote

Re: [algogeeks] Re: is it correct??

2011-06-15 Thread sunny agrawal
@kartik sachan This function is *not* defined in ANSI-C and is *not* part of C++, but is supported by some compilers. and +1 to Shachindra's post...i also think memory allocation will be from heap...not stack On Wed, Jun 15, 2011 at 2:34 PM, Shachindra A C sachindr...@gmail.comwrote:

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
i think u r wrong what if heap size -1 is 0 i think one should pick atleast one coin else game will draw On Wed, Jun 15, 2011 at 5:17 PM, immanuel kingston kingston.imman...@gmail.com wrote: First Player can always win. For each heap Pick heap-size - 1 coins if this is not the n-1th

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
consider the case. n = 2; heap 1 - no of coins 1 heap 2 - no of coins 2 On Wed, Jun 15, 2011 at 5:34 PM, sunny agrawal sunny816.i...@gmail.comwrote: i think u r wrong what if heap size -1 is 0 i think one should pick atleast one coin else game will draw On Wed, Jun 15, 2011 at 5:17 PM

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
the the heaps are of size 1 the Player 1 can win always. Thanks, Immanuel On Wed, Jun 15, 2011 at 5:36 PM, sunny agrawal sunny816.i...@gmail.comwrote: consider the case. n = 2; heap 1 - no of coins 1 heap 2 - no of coins 2 On Wed, Jun 15, 2011 at 5:34 PM, sunny agrawal sunny816.i

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
the other coin from heap1. Player 1 will take both the coins in heap 2. Thanks, Immanuel On Wed, Jun 15, 2011 at 6:33 PM, sunny agrawal sunny816.i...@gmail.comwrote: check out this case n = 2 both heaps having 2 coins player 2 will win i think On Wed, Jun 15, 2011 at 6:26 PM, immanuel

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
@Nitish n=2 heap 1 = 2 heap 2 = 3 Xor = 1 still player one can win :) On Wed, Jun 15, 2011 at 6:49 PM, sunny agrawal sunny816.i...@gmail.comwrote: @immanuel ohh, i read the Question wrong. :( i was thinking player1 is starting from least numbered heap and player 2 from highest no heap

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
i think solution depends on no of heaps having single coin if there are even number of such heaps player 1 will win if there are odd number of such heaps player 2 will win On Wed, Jun 15, 2011 at 6:49 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Player 1 can still win in this case: Player 1

Re: [algogeeks] DE Shaw Q

2011-06-15 Thread sunny agrawal
no that also wont work n=2 3,1 On Wed, Jun 15, 2011 at 6:59 PM, sunny agrawal sunny816.i...@gmail.comwrote: i think solution depends on no of heaps having single coin if there are even number of such heaps player 1 will win if there are odd number of such heaps player 2 will win On Wed

Re: [algogeeks] Re: Finding shortest path in 4-ary tree

2011-06-15 Thread sunny agrawal
@Raghavan if you want to fing the shortest path from a node u to v then its better to use BFS but according to your second post it seems you want to find path from root node to a leaf, in that case DFS seems to be best On Wed, Jun 15, 2011 at 9:56 PM, bittu shashank7andr...@gmail.com wrote: I

Re: [algogeeks] Re: spoj NKTM

2011-06-15 Thread sunny agrawal
0.00 with priority_queue stl for me :) On Thu, Jun 16, 2011 at 10:55 AM, Kunal Yadav kunalyada...@gmail.comwrote: Whats ur running time. Mine is 0.05 without using priority queque. On Wed, Jun 15, 2011 at 8:24 PM, kartik sachan kartik.sac...@gmail.comwrote: ya dude finally i applied that

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread sunny agrawal
Did you mean Shortest path from one node to another Use BFS i think we can find the shortest path On Tue, Jun 14, 2011 at 5:37 PM, Raghavan its...@gmail.com wrote: Hi, How to find the shortest path in a 4-ary tree in an optimal way? Node tree{ Node *left,*right,*top,*bottom; int val;

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread sunny agrawal
same as left right or top u can consider as each node as a cell of grid type of thing for easy understanding On Tue, Jun 14, 2011 at 5:59 PM, vaibhav agarwal vibhu.bitspil...@gmail.com wrote: What actually is meant by bottom pointer On Tue, Jun 14, 2011 at 5:57 PM, sunny agrawal sunny816.i

Re: [algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread sunny agrawal
it must be any general string Suffix tree approach seems best both in time and space complexity On Tue, Jun 14, 2011 at 7:36 PM, Navneet Gupta navneetn...@gmail.comwrote: This looks like a good problem. Could you confirm if string contains only two characters as you mentioned in both

Re: [algogeeks] Re: MS Question

2011-06-14 Thread sunny agrawal
, Arpit Sood soodfi...@gmail.com wrote: i meant if N = { 1, 1, 1, 2, 12} and M = { 1, 1, 3, 12} then answer should be = {1, 1, 12} On Mon, Jun 13, 2011 at 8:06 PM, sunny agrawal sunny816.i...@gmail.comwrote: no we can take care of duplicates without any extra memory modify 2nd step of my

Re: [algogeeks] [brain teaser ] Probability Riddle Loaded Revolver 13 june

2011-06-13 Thread sunny agrawal
Pull the Trigger Again ?? On Mon, Jun 13, 2011 at 1:01 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *Probability Riddle Loaded Revolver - 13* June * * * *** ** *Henry has been caught stealing cattle, and is brought into town for justice. The judge is his ex-wife Gretchen, who wants to

Re: [algogeeks] Re: How to remove duplicate element from array in one pass.

2011-06-13 Thread sunny agrawal
and the space requirement of the algorithm proposed does not approach infinity. here, even if n-infinity, input size would still be 8kb.. hence O(1) space. hope tat helps. On Jun 13, 12:38 pm, sunny agrawal sunny816.i...@gmail.com wrote: hello all, what if character are not ASCII

Re: [algogeeks] Re: MS Question

2011-06-13 Thread sunny agrawal
why do we need 2 bits at all ?? i think single bit per table entry will do. say table is T[1025], and array is A[M] 1. Go through the N sized array and set bit 0 of the hash table entry to 1 if it is present in the first array. 2. Go through the M sized array and if T[a[i]] is set then this

Re: [algogeeks] Re: MS Question

2011-06-13 Thread sunny agrawal
no we can take care of duplicates without any extra memory modify 2nd step of my previous solution as follows if T[a[i]] is set then this element is there in second array so report this element and Reset T[a[i]]. now no duplicates will be reported. and only 1025 bits will be required. any

Re: [algogeeks] help

2011-06-13 Thread sunny agrawal
because in all expression is evaluated to true. On Mon, Jun 13, 2011 at 10:02 PM, sahil sharma sahil18...@gmail.com wrote: ok i got the values of i ,j ,k ,.in all the 3 codes but can u please explain me how we get the value of m =1 in all the 3 program.? -- You received

Re: [algogeeks] help

2011-06-13 Thread sunny agrawal
m= ++i || ++j ++k; ++i will evauate to 3 and which is true so as next is || so next part will not be evaluated and m = true On Mon, Jun 13, 2011 at 11:34 PM, udit sharma sharmaudit...@gmail.comwrote: Bt y k=0, in 2nd code??? -- You received this message because you are subscribed to the

Re: [algogeeks] Swapping two variables without using a temporary variable

2011-06-13 Thread sunny agrawal
@tech rascal 10 = 01010 20 = 10100 -- xor = 0 = 30 why r u getting 1 ?? On Tue, Jun 14, 2011 at 2:28 AM, Supraja Jayakumar suprajasank...@gmail.com wrote: @Wladimir: Can you kindly explain the overflow and underflow you mentioned. Thanks Supraja J On Fri, Jun 10,

Re: [algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-12 Thread sunny agrawal
Piyush Sinha *ecstasy.piy...@gmail.com * -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] [brain teaser ] Find next number in series 10 june

2011-06-11 Thread sunny agrawal
@terence which game ?? On Fri, Jun 10, 2011 at 3:51 PM, Terence technic@gmail.com wrote: 42, 47 A popular game.:) On 2011-6-10 18:11, ankur aggarwal wrote: 42, 49 2011/6/10 • » νιρυℓ « • vipulmehta.1...@gmail.com 42, 47 just guessing according to the pattern. On Fri, Jun 10,

Re: [algogeeks] Algorithm or Program for convert word into number

2011-06-11 Thread sunny agrawal
may be a map can help that maps string to their integer values ans then using some set of rule to convert to a number On Sun, Jun 12, 2011 at 12:28 AM, Abhishek Goswami zeal.gosw...@gmail.comwrote: @I got one of my interview . I tried to solve this issue but could not it...I did googling but

Re: [algogeeks]

2011-06-10 Thread sunny agrawal
find common Ancestor of both. see if y lies on path from x or z to this ancestor O(lgn) On Fri, Jun 10, 2011 at 1:20 PM, aanchal goyal goyal.aanch...@gmail.comwrote: There is a binary tree(Not a BST) in which you are given three nodes x,y,z .Write a function which finds whether y lies in the

Re: [algogeeks]

2011-06-10 Thread sunny agrawal
but that will be O(n) i think On Fri, Jun 10, 2011 at 2:38 PM, Harshal hc4...@gmail.com wrote: can be solved using dfs. On Fri, Jun 10, 2011 at 2:27 PM, sunny agrawal sunny816.i...@gmail.comwrote: find common Ancestor of both. see if y lies on path from x or z to this ancestor O(lgn

Re: [algogeeks]

2011-06-10 Thread sunny agrawal
y lies on path from lca to z, but it doesn't lie on path from x to z. Am I missing something? On Fri, Jun 10, 2011 at 2:50 PM, sunny agrawal sunny816.i...@gmail.comwrote: but that will be O(n) i think On Fri, Jun 10, 2011 at 2:38 PM, Harshal hc4...@gmail.com wrote: can be solved using

Re: [algogeeks]

2011-06-10 Thread sunny agrawal
@ross if a parent pointer is there lca can be found in lgn and path can be traversed in lgn too why it cannot be lgn what is the problem ?? On Fri, Jun 10, 2011 at 3:06 PM, sunny agrawal sunny816.i...@gmail.comwrote: thats why i mentioned x OR z and i m considering parent pointer :) without

Re: [algogeeks] write an algo that deletes all negative integers without changing the order of remaining elements of the queue

2011-06-10 Thread sunny agrawal
First algorithm taht comes in mind deque a element if +ve enque again if(-ve) do nothing now question is terminating condition On Fri, Jun 10, 2011 at 3:44 PM, Sangeeta sangeeta15...@gmail.com wrote: write an algo that deletes all negative integers without changing the order of remaining

Re: [algogeeks] write an algo that deletes all negative integers without changing the order of remaining elements of the queue

2011-06-10 Thread sunny agrawal
initialy cal size of queue then apply a for loop On Fri, Jun 10, 2011 at 4:00 PM, sunny agrawal sunny816.i...@gmail.comwrote: First algorithm taht comes in mind deque a element if +ve enque again if(-ve) do nothing now question is terminating condition On Fri, Jun 10, 2011 at 3:44 PM

Re: [algogeeks]

2011-06-10 Thread sunny agrawal
using parent pointers untill we reach to lca. On Fri, Jun 10, 2011 at 3:59 PM, aanchal goyal goyal.aanch...@gmail.comwrote: @sunny finding lca in logn is fine, but how can we traverse the path in logn.. ? On Fri, Jun 10, 2011 at 3:50 PM, sunny agrawal sunny816.i...@gmail.comwrote: @ross

Re: [algogeeks] Re: write an algo that deletes all negative integers without changing the order of remaining elements of the queue

2011-06-10 Thread sunny agrawal
in this question i assumed that we need to write a function which takes an input a queue and function implements the required. we don't know how the queue is implemented, means we don't know about structure of the node. only 2 standard functions of queue enqueue and dequeue are known On Fri, Jun

Re: [algogeeks] FOR ALL INDIANS PLZ READ IT

2011-06-09 Thread sunny agrawal
yup, it works, i tried it!! On Thu, Jun 9, 2011 at 12:15 PM, Abdul Rahman Shariff ears7...@gmail.comwrote: did u try it ?? nd did u get the msg?? On Thu, Jun 9, 2011 at 1:06 AM, kartik sachan kartik.sac...@gmail.comwrote: Frnz govt of india has put a condition dat lokpal bill will b

Re: [algogeeks] solve the series

2011-06-09 Thread sunny agrawal
6 On Wed, Jun 8, 2011 at 10:31 PM, tech rascal techrascal...@gmail.comwrote: 20 ? 150 18 11 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group,

Re: [algogeeks] solve the series

2011-06-09 Thread sunny agrawal
series of some random numbers generated ussing some RNG no logic :P :P :P On Thu, Jun 9, 2011 at 12:29 PM, Arpit Sood soodfi...@gmail.com wrote: hey, what's the logic ? On Thu, Jun 9, 2011 at 12:22 PM, sunny agrawal sunny816.i...@gmail.comwrote: 6 On Wed, Jun 8, 2011 at 10:31

Re: [algogeeks] MS Interview

2011-06-09 Thread sunny agrawal
sum can overflow Xor method can also be applied to Q1. no need of numbers to be sorted. 2011/6/9 • » νιρυℓ « • vipulmehta.1...@gmail.com For 1. sum the numbers in the file, subtract it from sum of first 4 billion numbers. On Thu, Jun 9, 2011 at 3:44 PM, Navneet Gupta

Re: [algogeeks] MS Interview

2011-06-09 Thread sunny agrawal
yes, but using xor no need of ULL :) 2011/6/9 • » νιρυℓ « • vipulmehta.1...@gmail.com Sum wont overflow, ULL range will include sum. On Thu, Jun 9, 2011 at 3:52 PM, sunny agrawal sunny816.i...@gmail.comwrote: sum can overflow Xor method can also be applied to Q1. no need of numbers

Re: [algogeeks] Finding total number of inversions in an array in O(nlogn) complexity .

2011-06-09 Thread sunny agrawal
Discussed many times, 1) add some lines to merge sort 2) use Binary indexed tree for a faster version (i have not tried but get to know it can be done using binary indexed tree) On Thu, Jun 9, 2011 at 4:05 PM, D.N.Vishwakarma@IITR deok...@gmail.comwrote: Inversion means pair(i,j) such that ij

Re: [algogeeks] logic error:

2011-06-09 Thread sunny agrawal
check your this if condition if(tmap.end()-second=4) { ans=tmap.end()-first; } it should be == , not = On Thu, Jun 9, 2011 at 5:09 PM, John Hayes agressiveha...@gmail.com wrote: Hello every one i tried to code the same problem using STL mapsbut getting the RUN TIME

Re: [algogeeks] solve the series

2011-06-09 Thread sunny agrawal
hehe that was also random. :D -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] solve the series

2011-06-09 Thread sunny agrawal
the actual answer ? On Thu, Jun 9, 2011 at 5:46 PM, sunny agrawal sunny816.i...@gmail.comwrote: hehe that was also random. :D -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com

Re: [algogeeks] solve the series

2011-06-09 Thread sunny agrawal
seems like got it.. there is 150 days difference between 20/6(20 june) and 18/11(18 November) On Thu, Jun 9, 2011 at 6:14 PM, sunny agrawal sunny816.i...@gmail.comwrote: ha ha . i answer randomly...:) i don't like series questions, but this thread was sleeping so i posted for fun

Re: [algogeeks] Scheduling

2011-06-07 Thread sunny agrawal
Sort in decreasing order of Ci ? On Tue, Jun 7, 2011 at 8:22 AM, aanchal goyal goyal.aanch...@gmail.comwrote: Given n jobs, each ith job has a cost Ci associated with it. The waiting time for a job i is defined as Ci*Delay, where Delay is the number of days it takes from the first day to

Re: [algogeeks] Samsung Bangalore is hiring a lot!!!!

2011-06-07 Thread sunny agrawal
uninterested can filter messeges from sayanna...@gmail.com. :P On Tue, Jun 7, 2011 at 11:14 PM, sayan nayak sayanna...@gmail.com wrote: Multiple openings in Samsung Bangalore in following domains: 1. Wireless protocols 2. Android 3. Multimedia 4. Browser 5. mobile application.

Re: [algogeeks] Facebook Q

2011-06-07 Thread sunny agrawal
Replce all 0's with -1 -1 1 -1 -1 1 1 1 1 -1 perform the following operation a[i] = a[i-1] + a[i] for i = 1 to n-1 -1 0 -1 -2 -1 0 1 2 1 consider first element as 0 0 -1 0 -1 -2 -1 0 1 2 1 hash all these values to an array of size 2n+1 as sum will lie between -n to n where for 2 ij value hash to

Re: [algogeeks] 3 stacks using one array?

2011-06-03 Thread sunny agrawal
@Harshal Your Solution is optimal but i think in this question whenever there is some space available in array we should be able to use that space for either of the stack. in your solution this thing is missing. I don't know the solution but i think it can be improved in a way to get the required

Re: [algogeeks] Google Interview Question

2011-05-30 Thread sunny agrawal
@ Maksym Melnychok Fails i think some explanation say we have numbers 1 , 101 divide all by something to get 0.1, 0.101 simple sort will give you 0.101, 0.1 multiply all numbers to get original ones 101,1 join 1011 but correct answer should be 1101, isn't it ?? correct me if i m wrong ?? --

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max and min final answer will be max -min = Diameter of tree. correct me if i m wrong. -- You received this message

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
nope, it will not work :( got a case On Mon, May 30, 2011 at 11:57 PM, sunny agrawal sunny816.i...@gmail.comwrote: won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max

Re: [algogeeks] Re: Google Interview Question

2011-05-29 Thread sunny agrawal
@sravanreddy001 i don't find any cases for which my algo fails and its O(nlgn) i may be missing something can you tell any case where it fails On Sun, May 29, 2011 at 10:15 PM, sravanreddy001 sravanreddy...@gmail.comwrote: @vishal,Sanjeev.. for the inputs 18,187.. apply ur method.. 18 --

Re: [algogeeks] Re: Google Interview Question

2011-05-28 Thread sunny agrawal
@Logic King No, My algo will take only O(nlgn) where n is no of elements. what i mean by editing the comparision function cmp function of sort of algorithm.h sort(a,a+n, cmp); where cmp is the comparision function defined in my prev. post it will take equal no. of comparision as in sorting.

Re: [algogeeks] Re: strings

2011-05-27 Thread sunny agrawal
two strings can be mixed up anywhere .. and yes the ordering of the characters in the original strings must be preserved while constructing the third string ?? On Fri, May 27, 2011 at 1:04 PM, Senthil S senthil2...@gmail.com wrote: @ sunny agrawal : I misinterpreted the question .. but im

Re: [algogeeks] Re: strings

2011-05-26 Thread sunny agrawal
@senthil nopes, it will not work eg. S3 = cba S1 = a S2 = bc count matches but not interleaved On Thu, May 26, 2011 at 2:43 PM, Senthil S senthil2...@gmail.com wrote: Can it be done this way ..Take count of each alphabet for all the three strings and store separately.. Then for each alphabet

Re: [algogeeks] A Puzzling Puzzle

2011-03-16 Thread sunny agrawal
answer given by abhishek is the minimum no of flowers that need to be plucked in general no of flowers = 15*x/16 where x is no of flowers to be offered in the temple so 15,16 30,32 45,48 .. .. all are possible infinite solutions On Wed, Mar 16, 2011 at 10:36 PM, Kunal Patil kp101...@gmail.com

Re: [algogeeks] SPOJ PROBLEM

2011-03-07 Thread sunny agrawal
i think this will do, using DP pre compute the sum[i,j] that contains sum of all the values from i to j let M[i,j] is amount of money that can be made by selling the treats then M[i,j] = max(a[i] + sum[i+1,j]+M[i+1,j], a[j]+sum[i,j-1],M[i,j-1]) i haven't checked your solution and don't know are

Re: [algogeeks] Re: Robot Moving on The Maze..Need All possible Path

2011-03-03 Thread sunny agrawal
which is nothing but C(2n-2,n-1) Catalan Number i don't think so?? for a n*n grid answer is 2n!/n!n! but catalan number gives ans as 2n!/(n+1)!n! On Thu, Mar 3, 2011 at 8:12 PM, bittu shashank7andr...@gmail.com wrote: both DP Catalan Number solve this 1st Approach Catalan Number

Re: [algogeeks] Robot Moving on The Maze..Need All possible Path

2011-03-02 Thread sunny agrawal
@ashish its not that problem, read the question carefully On Wed, Mar 2, 2011 at 2:32 PM, Ashish Goel ashg...@gmail.com wrote: refer catalan numbers Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Mar 2, 2011 at 2:00 AM, bittu

Re: [algogeeks] Robot Moving on The Maze..Need All possible Path

2011-03-02 Thread sunny agrawal
understand why the problem is different from catalan number sunny... Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Mar 2, 2011 at 3:03 PM, sunny agrawal sunny816.i...@gmail.comwrote: @ashish its not that problem, read the question

Re: [algogeeks] Re: array(amazon microsoft)

2011-03-01 Thread sunny agrawal
@bittu Question is about to print entire array in sorted order, not searching an element On Wed, Mar 2, 2011 at 4:13 AM, bittu shashank7andr...@gmail.com wrote: @all after 32 Message Discussion I know Everyone is looking for O(N) solution well it seems odd how we can search an element in a

Re: [algogeeks] Re: Robot Moving on The Maze..Need All possible Path

2011-03-01 Thread sunny agrawal
DP initialize ways[][] m*atrix to zero* * * *if 0,0 is blocked no solution else* *ways[0][0] = 1* *for i in range 1 to N-1 if ways[0][i] is not blocked ways[0][i] = ways[0][i-1]* *for i in range 1 to N-1 if ways[i][0] is not blocked ways[i][0] = ways[i-1][0]* * * *for i in range 1 to N-1* *for j

Re: [algogeeks] Search element in 2D row-wise colum-wise sorted matrix

2011-03-01 Thread sunny agrawal
step 1: start at Bottom-left corner step 2: if equal then return else if element is less than number to be searched for then it cannot be in that row go up step 3: if element is greater than number to be searched for then it cannot be in that column go ahead Repeat untill you got the

Re: [algogeeks] printing without loop

2011-03-01 Thread sunny agrawal
for general case to print i to n create a class with one static member i initialized to 0 in constructor of the class increment i and print i create n objects of the class in main -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Re: array(amazon microsoft)

2011-03-01 Thread sunny agrawal
You are given a array with rows sorted and column sorted. You have to print entire array in sorted order. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] printing without loop

2011-02-28 Thread sunny agrawal
int i=1; #define PRINT1 couti++endl; #define PRINT2 PRINT1 PRINT1 #define PRINT4 PRINT2 PRINT2 #define PRINT8 PRINT4 PRINT4 #define PRINT16 PRINT8 PRINT8 #define PRINT32 PRINT16 PRINT16 #define PRINT64 PRINT32 PRINT32 int main() { //as 100 = (1100100); we need to use PRINT64, PRINT32, and

Re: [algogeeks] UVA problem

2011-02-21 Thread sunny agrawal
as there are only 6 possibilities, i think this will do BCG BGC GCB GBC CBG CGB for each find no of moves, and print min On Tue, Feb 22, 2011 at 2:51 AM, rgap rgap...@gmail.com wrote: Hi, I need help with this problem

Re: [algogeeks] Re: question at K10

2011-02-16 Thread sunny agrawal
and also void change() { // Code here int x = 1; int*p= x; while(*p != 5) p++; *p = 10; } On Wed, Feb 16, 2011 at 8:02 AM, Balaji S balaji.ceg...@gmail.com wrote: The solution is.. _AX = 10; can anyone explain?? -- You received this message because you are subscribed to the

<    1   2   3   4   >