How are voracious fish ordered in a river?

How are voracious fish ordered in a river?

You are given two non-empty zero-indexed arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q.

How to compute for each fish by codility?

# Compute for each fish ifB[index]==1: # This fish is flowing downstream. It would # NEVER meet the previous fishs. But possibly # it has to fight with the downstream fishs. downstream.append(A[index])

Is there a solution to Dominator by codility?

Solution to Dominator by codility» 34 Replies to “Solution to Fish by codility” Maxsays: March 14, 2014 at 7:19 am Hi Shen, what is the use of ‘downstream_count’ if you increase it everytime you push to ‘downstream’ stack and decrease it everytime you pop from ‘downstream’ stack, and you have len(downstream) at your disposal?

How are the fish in a river numbered?

The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q. Initially, each fish has a unique position. Fish number P is represented by A [P] and B [P]. Array A contains the sizes of the fish.

How are the numbers of fish represented in codility?

The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q. Initially, each fish has a unique position. Fish number P is represented by A [P] and B [P]. Array A contains the sizes of the fish.

How are the fish numbered in a river?

Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q. Initially, each fish has a unique position. Fish number P is represented by A [P] and B [P].

How are two fish moving along a river?

0 represents a fish flowing upstream, 1 represents a fish flowing downstream. If two fish move in opposite directions and there are no other (living) fish between them, they will eventually meet each other. Then only one fish can stay alive − the larger fish eats the smaller one.