CJCoding With Joseph
15free / daySign inCreate account

Index Of Target

Write index_of(values: list[int], target: int, position: int) -> int that returns the index of the first occurrence of target in values at or after the given position, or -1 when it is not there, by recursion that moves the position forward instead of slicing: when position equals len(values) the search has run off the end, so return -1; when the value at position equals target return position; otherwise recurse with position + 1. Do NOT write a main block or any top-level test code; the tests construct the calls with a starting position of 0. Input: two lines, the list as integers separated by spaces (it may be empty) and then the target, which the tests read and pass to your function before printing the value it returns.

Expected Output:

2

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Recursion
📥 Auto-Input:
5 8 2 9\n2\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.