Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a binary search algorithm in R to find an element in a sorted vector.

Hard

Problem Statement

Implement a binary search algorithm in R to find an element in a sorted vector.

Sample Input

Vector: c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Target: 7

Sample Output

Element found at index: 7

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure binary_search <- function(vector, target) { # Your logic here } # Call the function
Log in or sign up to run or submit your code.Log inSign up
Input
Vector: c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Target: 7
Expected Output
Element found at index: 7