Binary Search

Medium Recursion
Solve in Playground →

Problem Statement

Write a recursive Python function to perform binary search on a sorted list of numbers and return the index of the target element, or -1 if not found.

Input Format

Line 1: Space-separated sorted integers. Line 2: Target integer.

Output Format

Print the index or -1.

Constraints

1 <= len(arr) <= 50

Sample Input

1 3 5 7 9
5

Sample Output

2

Explanation

Compare middle element with target and recursively search left or right halves.

Starter Code

def binary_search(arr, low, high, target):
    # Write your code here
    pass

arr = list(map(int, input().split()))
target = int(input())
print(binary_search(arr, 0, len(arr) - 1, target))

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used