Loading...
Loading...
Loading...
A store keeps its product names in a list, and a name can appear several times. Answer q lookups. For each query print the first and the last position of the name in the list, or say that it is not found.
<name>: first <i>, last <j> or <name>: not found.Example
Input
5 Pen Bag Pen Mug Pen 3 Pen Cap Mug
Output
Pen: first 0, last 4 Cap: not found Mug: first 3, last 3
Try the problem first. Open one hint at a time.
indexOf gives the first position and lastIndexOf the last one; both return -1 when the name is missing.
Check the first result against -1 once, then print both.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor