Originally Posted by
rharvell
Write an algorithm that returns the index of the last occurrence of the value key
That means start at the end, or the last element, and work toward the front looking for the requested value. For example, in 12 11 12 23, it means start at 23, is 23 the key (12), no, keep looking. Move back to 12. Is 12 the key (12), yes. Return it. Note that it is in index 2 not index 0. Also beware that this is to return the key, not the positional index, and 0 represents "not found"
Originally Posted by
rharvell
in a sequence s1, …,sn.
This just means the set of elements can be any given length.
Originally Posted by
rharvell
If key is not in the sequence, the algorithm returns 0.
If the requested key (12 in the example) is not found, return 0.