Yes...Kunal is right !!! It doesn't matter whether getMax() removes element or not, because MAX value is maintained in each node of stack which is pointing to the maximum of the value present below or up to that element... So if stack is 5 3 2 8 6 Then nodes would have following structure 5 max --> 5 3 max --> 5 2 max --> 5 8 max --> 8 6 max --> 8
U shud have got it now.... On Sat, Mar 26, 2011 at 4:06 PM, kunal srivastav <[email protected] > wrote: > maintain a pointer to the max element so far in every element of the > stack.. > while push - if the new element is greater than the stack->top->max then > add the new element at the top and hence make the max pointer of the new > element point to itself, otherwise the new element is less than the max till > yet and hence point the max part of the new element to the max part of the > element at the top > > thus at each point the max pointer of the top most element points to the > current max of the stack > > pop - usual, no need to do anything :) > > see if you are able to follow this logic. getmax() is O(1) because you just > need to deference the max part of the top most element at any time > > On Sat, Mar 26, 2011 at 3:43 PM, balaji a <[email protected]> wrote: > >> yeah it wont remove the element...GetMax() only returns the maximum >> element added so far...... >> >> >> On Thu, Mar 24, 2011 at 9:42 AM, MK <[email protected]> wrote: >> >>> Actually, you probably mean that GetMax() does not remove it from the DS? >>> >>> Sorry for the hasty conclusion. >>> >>> On Thu, Mar 24, 2011 at 12:11 AM, MK <[email protected]> wrote: >>> > "2) Design a DS that would do Push(),Pop(), and GetMax() elements at >>> > complexity O(1)" >>> > >>> > Are you sure you remember this correctly? This would give you a way of >>> > sorting in O(1). >>> > >>> > Thanks.. >>> > >>> > >>> > >>> > On Thu, Mar 24, 2011 at 12:09 AM, balaji a <[email protected]> >>> wrote: >>> >> The main thing they are testing is Problem Solving and the Algorithm >>> >> Designing ability. Coding Ability is only next. If you have good >>> knowledge >>> >> in Data Structures and good Problem Solving skills with coding ability >>> you >>> >> can easily crack through the interview. This is what i infered from my >>> >> experience. >>> >> >>> >> On Thu, Mar 24, 2011 at 12:33 AM, kunal srivastav >>> >> <[email protected]> wrote: >>> >>> >>> >>> hi people, could someone tell me in detail what all things to prepare >>> for >>> >>> amazon including the resources to consult for the same?? it would be >>> really >>> >>> helpful >>> >>> >>> >>> On Thu, Mar 24, 2011 at 12:11 AM, Akash Mukherjee < >>> [email protected]> >>> >>> wrote: >>> >>>> >>> >>>> kul man...wud appreciate if u cud post your question >>> >>>> >>> >>>> On Wed, Mar 23, 2011 at 11:28 PM, balaji a <[email protected] >>> > >>> >>>> wrote: >>> >>>>> >>> >>>>> hi i got till the third round of technical interview out of the >>> four >>> >>>>> rounds and got eliminated in third round.....anyways thnx for ur >>> support >>> >>>>> dude :-) >>> >>>>> >>> >>>>> On Tue, Mar 22, 2011 at 12:51 PM, balaji a < >>> [email protected]> >>> >>>>> wrote: >>> >>>>>> >>> >>>>>> Thnx :-) I am from SSN College of Engineering,Chennai.... >>> >>>>>> l >>> >>> >>> >>> >>> >>>>>> >>> >>>>>> On Tue, Mar 22, 2011 at 12:28 PM, Akash Mukherjee < >>> [email protected]> >>> >>>>>> wrote: >>> >>>>>>> >>> >>>>>>> u r welcome :), nd all the best for ur test.....btw, which clg?? >>> >>>>>>> >>> >>>>>>> On Tue, Mar 22, 2011 at 11:45 AM, guru <[email protected]> >>> >>>>>>> wrote: >>> >>>>>>>> >>> >>>>>>>> Thank you very much for the info friend....And sure will give u >>> a >>> >>>>>>>> treat :-) >>> >>>>>>>> >>> >>>>>>>> On Mar 22, 11:02 am, Akash Mukherjee <[email protected]> >>> wrote: >>> >>>>>>>> > hey, dis is what i was told by a friend working @ amazon - >>> >>>>>>>> > >>> >>>>>>>> > Sometimes they do go to the level of the subject basics like >>> OS or >>> >>>>>>>> > DS but >>> >>>>>>>> > you should be able to tackle these if you had studied well. No >>> >>>>>>>> > separate prep >>> >>>>>>>> > is needed. >>> >>>>>>>> > >>> >>>>>>>> > Few Favs DS & Algos ( i should get treat for revealing >>> this.;)... ) >>> >>>>>>>> > 1) All Trees (Binary for sure) >>> >>>>>>>> > 2) Graphs >>> >>>>>>>> > 3) Sorting Algos >>> >>>>>>>> > 4) Heaps >>> >>>>>>>> > "Let us C" ... though clichéd gives a good insight. If you can >>> find >>> >>>>>>>> > time. >>> >>>>>>>> > >>> >>>>>>>> > can u tell a bit more about your profile?? fresher?? >>> >>>>>>>> > >>> >>>>>>>> > On Tue, Mar 22, 2011 at 11:20 AM, guru < >>> [email protected]> >>> >>>>>>>> > wrote: >>> >>>>>>>> > > Hi geeks, >>> >>>>>>>> > > tomorrow i am having Amazon.com's Coding round followed >>> by >>> >>>>>>>> > > Interview...pls suggest some tips to help me out... >>> >>>>>>>> > >>> >>>>>>>> > > -- >>> >>>>>>>> > > You received this message because you are subscribed to the >>> >>>>>>>> > > Google Groups >>> >>>>>>>> > > "Algorithm Geeks" group. >>> >>>>>>>> > > To post to this group, send email to >>> [email protected]. >>> >>>>>>>> > > To unsubscribe from this group, send email to >>> >>>>>>>> > > [email protected]. >>> >>>>>>>> > > For more options, visit this group at >>> >>>>>>>> > >http://groups.google.com/group/algogeeks?hl=en. >>> >>>>>>>> >>> >>>>>>>> -- >>> >>>>>>>> You received this message because you are subscribed to the >>> Google >>> >>>>>>>> Groups "Algorithm Geeks" group. >>> >>>>>>>> To post to this group, send email to [email protected] >>> . >>> >>>>>>>> To unsubscribe from this group, send email to >>> >>>>>>>> [email protected]. >>> >>>>>>>> For more options, visit this group at >>> >>>>>>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>>>>>>> >>> >>>>>>> >>> >>>>>>> -- >>> >>>>>>> You received this message because you are subscribed to the >>> Google >>> >>>>>>> Groups "Algorithm Geeks" group. >>> >>>>>>> To post to this group, send email to [email protected]. >>> >>>>>>> To unsubscribe from this group, send email to >>> >>>>>>> [email protected]. >>> >>>>>>> For more options, visit this group at >>> >>>>>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>>>>> >>> >>>>>> >>> >>>>>> >>> >>>>>> -- >>> >>>>>> A.Balaji >>> >>>>>> >>> >>>>> >>> >>>>> >>> >>>>> >>> >>>>> -- >>> >>>>> A.Balaji >>> >>>>> >>> >>>>> -- >>> >>>>> You received this message because you are subscribed to the Google >>> >>>>> Groups "Algorithm Geeks" group. >>> >>>>> To post to this group, send email to [email protected]. >>> >>>>> To unsubscribe from this group, send email to >>> >>>>> [email protected]. >>> >>>>> For more options, visit this group at >>> >>>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>>> >>> >>>> -- >>> >>>> You received this message because you are subscribed to the Google >>> Groups >>> >>>> "Algorithm Geeks" group. >>> >>>> To post to this group, send email to [email protected]. >>> >>>> To unsubscribe from this group, send email to >>> >>>> [email protected]. >>> >>>> For more options, visit this group at >>> >>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >>> >>> >>> >>> >>> >>> -- >>> >>> thezeitgeistmovement.com >>> >>> >>> >>> -- >>> >>> You received this message because you are subscribed to the Google >>> Groups >>> >>> "Algorithm Geeks" group. >>> >>> To post to this group, send email to [email protected]. >>> >>> To unsubscribe from this group, send email to >>> >>> [email protected]. >>> >>> For more options, visit this group at >>> >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >>> >> >>> >> >>> >> -- >>> >> A.Balaji >>> >> >>> >> -- >>> >> You received this message because you are subscribed to the Google >>> Groups >>> >> "Algorithm Geeks" group. >>> >> To post to this group, send email to [email protected]. >>> >> To unsubscribe from this group, send email to >>> >> [email protected]. >>> >> For more options, visit this group at >>> >> http://groups.google.com/group/algogeeks?hl=en. >>> >> >>> > >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >> >> >> -- >> A.Balaji >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > thezeitgeistmovement.com > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
