Previous Next
0 / 15
Module DEMO-33-67DEMO-OOP-33

Binary Search Position

DEMO-OOP-33 โ€ข Object Oriented Programming

Browser-only practice

Problem Statement

Read seven sorted integers and a target value, then print the binary-search index for the target or -1 if it is missing.

Input Format

Input is given as whitespace-separated tokens in this order:

  1. value 1
  2. value 2
  3. value 3
  4. value 4
  5. value 5
  6. value 6
  7. value 7
  8. target value

Output Format

Print the exact report in this order:

  1. Index

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
1
3
5
7
9
11
13
7
Index: 3
Input: value 1 = 1, value 2 = 3, value 3 = 5, value 4 = 7, value 5 = 9, value 6 = 11, value 7 = 13, target value = 7.
Key calculation(s): values = {1, 3, 5, 7, 9, 11, 13} | left = 0 | "Index: " + found = "Index: 3".
Output:
Index: 3
Sample #2
Public sample
2
4
6
8
10
12
14
14
Index: 6
Input: value 1 = 2, value 2 = 4, value 3 = 6, value 4 = 8, value 5 = 10, value 6 = 12, value 7 = 14, target value = 14.
Key calculation(s): values = {2, 4, 6, 8, 10, 12, 14} | left = 0 | "Index: " + found = "Index: 6".
Output:
Index: 6

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings