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 accountHow 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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.