It's a little trickier than it seems at first sight, but this should work:
(define (last lst key)
(cond ((null? lst) '())
((member key (cdr lst))
(cons (car lst) (last (cdr lst) key)))
(else '())))
The key insight is that you should use member
to check if the element is still present in the list (that will tell us when we've found its last occurrence). Also you should consider two special cases - what happens if the list is empty, or if the key is not in the list? In both cases I'm returning an empty list. For example:
(last '("hi" "how" "are" "you") "you")
=> '("hi" "how" "are")
(last '("hi" "how" "are" "how" "you") "how")
=> '("hi" "how" "are")
(last '("hi" "how" "are" "how" "you") "today")
=> '()
(last '() "empty")
=> '()