Re: [algogeeks] Divide the array into groups

2011-01-29 Thread Rohit Saraf
I don't see why you need O(n^2) time for rearranging. It can be done in O(n log n) if you maintain the index along with every element. Then reordering would mean sort as per the indices. -- Rohit Saraf Third Year Undergraduate, Dept. of Computer Scie

Re: [algogeeks] Divide the array into groups

2011-01-29 Thread snehal jain
list all groups...with their elements On Sun, Jan 30, 2011 at 12:32 PM, nishaanth wrote: > so whats the required outputlist all possiblities or anything else? if > its just this one output...then it sounds trivial > > > On Sun, Jan 30, 2011 at 11:43 AM, snehal jain wrote: > >> @nishanth

Re: [algogeeks] Divide the array into groups

2011-01-29 Thread nishaanth
so whats the required outputlist all possiblities or anything else? if its just this one output...then it sounds trivial On Sun, Jan 30, 2011 at 11:43 AM, snehal jain wrote: > @nishanth > divide into groups ( not necessarily 2) in as many group as possible.. such > that elements in each

Re: [algogeeks] Re: Minimum positive-sum subarray

2011-01-29 Thread snehal jain
@nishanth oh ya right.. On Sun, Jan 30, 2011 at 11:27 AM, nishaanth wrote: > @snehalno its incorrect..consider the following example > -2 3 > > The answer to this problem is the entire array with sum 1.(not the min of > positive number) > > > > On Sun, Jan 30, 2011 at 11:00 AM, snehal jai

Re: [algogeeks] Divide the array into groups

2011-01-29 Thread snehal jain
@nishanth divide into groups ( not necessarily 2) in as many group as possible.. such that elements in each group is consecutive another example to clearify A= { 9,7, 13, 11,6,12,8,10,3, 4, 2, 16,14,17,13,15) ans <9,7,13,11,6,12,8,10> <3,4,2> <16,14,17,13,15> On Sun, Jan 30, 2011 at 11:32 AM, ni

Re: [algogeeks] Divide the array into groups

2011-01-29 Thread nishaanth
@snehal..i guess you are missing something in the question...divide it into 2 groups such that (there should be some other condition or criterion). On Sun, Jan 30, 2011 at 11:29 AM, snehal jain wrote: > my approach > > sort in nlogn and then while traversing the array put the elements in a >

Re: [algogeeks] Divide the array into groups

2011-01-29 Thread snehal jain
my approach sort in nlogn and then while traversing the array put the elements in a group till they are consecutive . when a[i+1]!=a[i]+1 then put a[i+1] in different group.. now we need to rearrange elements in the group so that they are according to the given array.. but that will make it O(n^2)

Re: [algogeeks] Re: Minimum positive-sum subarray

2011-01-29 Thread nishaanth
@snehalno its incorrect..consider the following example -2 3 The answer to this problem is the entire array with sum 1.(not the min of positive number) On Sun, Jan 30, 2011 at 11:00 AM, snehal jain wrote: > a friend of mine was asked this question in google interview.. > > according to

Re: [algogeeks] Re: Amazon Again

2011-01-29 Thread nishaanth
@Wei.Qi Can you clarify when your algorithm terminates and also what is the running time of the algorithm ? On Sun, Jan 30, 2011 at 9:46 AM, yq Zhang wrote: > can you prove it? > > On Jan 29, 2011 6:38 PM, "Wei.QI" wrote: > > > > Starting with any pump A, try to finish the circle, if at pum

Re: [algogeeks] Re: Minimum positive-sum subarray

2011-01-29 Thread snehal jain
a friend of mine was asked this question in google interview.. according to me the min element in the array is the answer provided that its not zero.. as 1 element can also be a subarray. but that would solve the problem in O(n) only.. ( this is what i understood) am i missing anything..? please h

Re: [algogeeks] Re: Amazon Again

2011-01-29 Thread yq Zhang
can you prove it? On Jan 29, 2011 6:38 PM, "Wei.QI" wrote: > > Starting with any pump A, try to finish the circle, if at pump B that can not reach pump B+1, it means all pumps from A to B can not finish the circle (it will go broke at pump B), then just start with B+1. After go through all the pum

Re: [algogeeks] Re: Amazon Again

2011-01-29 Thread Wei.QI
Starting with any pump A, try to finish the circle, if at pump B that can not reach pump B+1, it means all pumps from A to B can not finish the circle (it will go broke at pump B), then just start with B+1. After go through all the pumps start from some pump, we got an answer. if we go back to pump

Re: [algogeeks] Frequently one of the Top Question Asked in Amazon

2011-01-29 Thread saurabh gupta
what do you mean by spiral order ? On Sat, Jan 29, 2011 at 8:25 PM, bittu wrote: > Convert BT in to DLL such that DLL represents the Sprial order > traversal of BT. > > "Inplace" > > its Written Test Question & They wants Exact Working Code...Not > Approach..Be Clear..Try to provide best solutio

[algogeeks] Re: Minimum positive-sum subarray

2011-01-29 Thread Dan
On Jan 21, 1:05 am, snehal jain wrote: > In this variation of the Maximum-Sum Subarray Problem, you are given a > one-dimensional array A[1 : n] of positive or negative numbers, and > you are asked to find a subarray A[i : j] such that the sum of its > elements is (1) strictly greater than zero, a

[algogeeks] Re: Google Question

2011-01-29 Thread Saikat Debnath
@ Sankalp : plz explain this line of yours : No. of As=A*(total number of keystrokes) , gives us a bound . We should have a lower bound as this , we can always get this much As On Jan 29, 5:32 pm, sankalp srivastava wrote: > We can do it Using a binary search approach (The cost function is > mon

[algogeeks] CFP: The 2011 International Conference on Software Engineering Research and Practice (SERP'11), USA, July 18-21, 2011

2011-01-29 Thread A. M. G. Solo
   CALL  FOR  PAPERS and   Call For Workshop/Session Proposals      SERP'11 The 2011 International Conference on Software    Engineering Research and Practice      Date and Location: Ju

Re: [algogeeks] Minimum positive-sum subarray

2011-01-29 Thread snehal jain
anyone here? On Fri, Jan 21, 2011 at 2:35 PM, snehal jain wrote: > In this variation of the Maximum-Sum Subarray Problem, you are given a > one-dimensional array A[1 : n] of positive or negative numbers, and > you are asked to find a subarray A[i : j] such that the sum of its > elements is (1) s

[algogeeks] Re: Frequently one of the Top Question Asked in Amazon

2011-01-29 Thread juver++
@bittu offtopic: could you please tell us why do you use uppercase letters in > 50% of the words?! -- 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 grou

[algogeeks] Frequently one of the Top Question Asked in Amazon

2011-01-29 Thread bittu
Convert BT in to DLL such that DLL represents the Sprial order traversal of BT. "Inplace" its Written Test Question & They wants Exact Working Code...Not Approach..Be Clear..Try to provide best solutions Thanks & Regards Shashank " "The best way to escape from a problem is to solve it." -- Yo

[algogeeks] Re: Using prefix sum to calculate maximum subarray in 2D

2011-01-29 Thread AKO
the paper: http://www.cosc.canterbury.ac.nz/research/reports/MastTheses/2007/mast_0705.pdf On Jan 29, 3:31 pm, AKO wrote: > I am a rookie working with algorithms and especially implementing > them. > > Im trying to implement the brute force method using the prefix sum of > the NxN-array > I got t

[algogeeks] Using prefix sum to calculate maximum subarray in 2D

2011-01-29 Thread AKO
I am a rookie working with algorithms and especially implementing them. Im trying to implement the brute force method using the prefix sum of the NxN-array I got this piece of code, in which i want to return the sum of maximum subarray. prefix sum means that the array {{2, -1},{4, 19}} becomes {{

[algogeeks] Re: Amazon Again

2011-01-29 Thread sankalp srivastava
I'm sure you have misstated the problem statement just find out the total path length and return the first petrol pump which gives you the required milage go greedy On Jan 28, 5:09 pm, bittu wrote: > There are N petrol pumps along a circular path. Every petrol pump > gives some amount of fixed p

[algogeeks] Re: Google Question

2011-01-29 Thread sankalp srivastava
We can do it Using a binary search approach (The cost function is monotonic over here , so we can use binary search) No. of As=A*(total number of keystrokes) , gives us a bound . We should have a lower bound as this , we can always get this much As Take the initial value as high and low as possi

[algogeeks] Re: Good Maths Question

2011-01-29 Thread sankalp srivastava
Yuo might wanna check out The latest codeforces beta round problem C . On Jan 28, 8:34 pm, nishaanth wrote: > @All... According to the constraints(SPOJ problem) wont this dp solution > time out ? > > On Tue, Jan 25, 2011 at 12:23 AM, sankalp srivastava < > > > > > > richi.sankalp1...@gmail.com> w

[algogeeks] Re: Prime Numbers

2011-01-29 Thread sankalp srivastava
Okay I got it myself @OP This can be done in O(n*k*logn) where k is of order 10^3 at the very max , when u need a prime like 1 trillion On Jan 28, 6:44 pm, sankalp srivastava wrote: > Correct me if I'm wrong , but according to you , will this be the > approach ? > > boolean array[10]; > int

[algogeeks] Re: zig zag

2011-01-29 Thread sankalp srivastava
No , actually it's not ... it's O(n^2) , I misunderstood the "subsequence" thing , it could be discontinuous .. we , then need to find the maximum of dp[l] ... the second term makes sure that the sign of the two quantities is alternating i.e. positive or negative ! On Jan 29, 11:06 am, nishaanth

Re: [algogeeks] Re: Amazon Question

2011-01-29 Thread Ritu Garg
Yes,it works for binary search tree only On Sat, Jan 29, 2011 at 2:22 PM, nphard nphard wrote: > Looks good. I concede that it works for a Binary "Search" Tree. > > On Sat, Jan 29, 2011 at 1:35 AM, Ritu Garg wrote: > >> @nphard,see the following approach carefully to know *if right pointer is >>

Re: [algogeeks] Re: Amazon Question

2011-01-29 Thread nphard nphard
Looks good. I concede that it works for a Binary "Search" Tree. On Sat, Jan 29, 2011 at 1:35 AM, Ritu Garg wrote: > @nphard,see the following approach carefully to know *if right pointer is > pointing to right child or in order successor* > * > *Q = node->right > IF (Q is not NULL) > { >