+ 6
Can anyone write a code for this in c++ or any other programming language?
Adam is very fond of reading books. He has given rating to each book according to his likes and dislikes. He reads books one after other and he becomes happy everytime when he finishes a book and starts a higher rating book. Given the No. Of books and rating for each book, find maximum number of times he will become happy.
5 Answers
+ 6
Thank you:-)
+ 6
can you explain by writing algorithm?
+ 5
ill give you the general algorithm
int timesHappy = 0;
if (thisBookRating > previousBookRating) {
timesHappy++;
}
+ 2
there is actually some slightly complicated sorting to do here - you need to order the books so as to maximize the number of times you go from a low book to a high one.
say you have 10 books. 5 are rated 0, 5 are rated 5. if you order them sequentially (0000055555), he is happy once. if you alternate low and high, he is happy 5 times.
+ 1
hi, I think It's theory of probability, where we have some array( size equal number of books) when every element has value 0 or 1 (dislike/ like). Then we have to mix (swap randomly address of every element ) and then we be able to sort this array increasing value of happy if condition meets the requirements of task .