← Unit 4 · all exercises
Saved in this browser only

The last position

Return the position of the LAST time the target appears, or -1 when it is absent. Counting starts at 0.

int lastIndexOf(int[] values, int target)

Solution.java
Loading editor…
Results

Examples

  • Solution.lastIndexOf(new int[]{1, 2, 1}, 1) → 2
  • Solution.lastIndexOf(new int[]{1, 2, 3}, 9) → -1

There are also 3 hidden tests you can't see. Solve the problem, not the examples.