The remaining two fish, number 0 and 4, never meet and therefore stay alive. Finally, it meets fish number 4 and is eaten by it. Fish number 1 meets fish number 2 and eats it, then it meets fish number 3 and eats it too. Initially all the fish are alive and all except fish number 1 are moving upstream. The goal is to calculate the number of fish that will stay alive.įor example, consider arrays A and B such that: A = 4 B = 0 That is, fish moving in the same direction never meet. We assume that all the fish are flowing at the same speed. If A > A then Q eats P, and Q will still be flowing upstream.If P and Q are two fish and P A then P eats Q, and P will still be flowing downstream, Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. You are given two non-empty arrays A and B consisting of N integers.
0 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |