From 0de38e0de98907215b467cce709a0f821c26aa3b Mon Sep 17 00:00:00 2001 From: Joshua Yoon Date: Mon, 8 Jun 2026 16:25:18 -0500 Subject: [PATCH] Interview 1 --- Problem1.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Problem1.java b/Problem1.java index 8b137891..b60cc0ec 100644 --- a/Problem1.java +++ b/Problem1.java @@ -1 +1,33 @@ +public class Problem1 { + + public static void main(String[] args) { + + //find 4 in array = [1,2,3,5,6,7] using binary search + int[] arr = {1, 2, 3, 5, 6, 7}; + int target = 4; + int result = binarySearch(arr, target); + if (result == -1) { + System.out.println("Element not found in the array."); + } else { + System.out.println("Element found at index: " + result); + } + + } + public return int binarySearch(int[] arr, int target) { + int left = 0; + int right = arr.length - 1; + + while (left <= right) { + int mid = left + (right - left) / 2; + if (arr[mid] == mid +1){ + left = mid +1; + } else { + right = mid -1; + } + } + + return left + 1; + } +} + \ No newline at end of file