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!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

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 Feb 2026

Contest runs February 1 - 28. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.