Re: [algogeeks] Amazon : Find popular cost

2012-06-10 Thread Akshat Sapra
Here, we can use hashmap and use an extra variable max_till_now that will
keep track of maximum element occured to us till now while updating.

Time complexity of solution will be O(n)

max_till_now = 0;

for ( int i = 0; i  arr.size(); i++ ) {
 hashmap[arr[i]] += 1;
if ( hashmap[arr[i]]  max_till_now )  max_till_now =
hashmap[arr[i]];
}

print(max_till_now);

-- 


Akshat Sapra
Under Graduation(B.Tech)
IIIT-Allahabad(Amethi Campus)
*--*
sapraaks...@gmail.com
akshatsapr...@gmail.com
rit20009008@ rit20009...@gmail.comiiita.ac.in

-- 
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 options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Amazon : Find popular cost

2012-05-31 Thread g4ur4v
How to find popular cost of the books,
say
   book1 $10
   book2 $20
   book3 $40
   book4 $50
   book5 $10
   book6 $20


http://www.careercup.com/question?id=13720752

-- 
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 options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Amazon : Find popular cost

2012-05-31 Thread atul anand
here find popular post means to find most repeated costso we can
use combination of max-heap and hashtable.

hashtable is required to keep track for distinct cost.

so if cost is not present in hashtable then add it to the hashtable
and then add it to the Max-heap with counter value =1...then hepify.
next time we find that cost in hashtable then we just need to
increment counter of that cost in heap and thne hepify.At any point of
time ...element at the top is the element with popular cost.

On 5/31/12, g4ur4v gauravyadav1...@gmail.com wrote:
 How to find popular cost of the books,
 say
book1 $10
book2 $20
book3 $40
book4 $50
book5 $10
book6 $20


 http://www.careercup.com/question?id=13720752

 --
 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 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.