Implement a binary search algorithm to find the index of a target value in a sorted list of integers. Return the index if found, or -1 if not found. The input list is guaranteed to be sorted in ascending order.

Examples:

Input: sortedList = [1, 3, 5, 7, 9, 11], target = 7 Output: 3 Explanation: The target value 7 is found at index 3 Input: sortedList = [2, 4, 6, 8, 10], target = 5 Output: -1 Explanation: The target value 5 is not found in the list Input: sortedList = [1, 2, 3, 4, 5], target = 1 Output: 0 Explanation: The target value 1 is found at index 0
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay July 2026

Contest runs July 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In