Practice
Find an Item in the Sorted List
2024/Oct/Nov·Variant 2
EASYArrays
ItemList (5 strings) is already sorted alphabetically. Write function FindItem() that searches for Target and returns its 1-based position as a string, or "Not found" if it is not present.
Input: 5 sorted item names, then the target to find.
Output: The position, or "Not found".
Example:
Input: Book
Eraser
Marker
Pen
Ruler
Marker
Output: 3
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Middle item found
Inputs: Book, Eraser, Marker, Pen, Ruler, Marker
Expected: 3
Test 2: Target not in the list
Inputs: Book, Eraser, Marker, Pen, Ruler, Zebra
Expected: Not found