Skip to content

Commit d818eda

Browse files
committed
feat: Implement max and maxRange methods to find maximum element in full or partial array
🧠 Logic: - `maxRange(arr, start, end)` finds the maximum value in a subarray from index `start` to `end`. - Handles edge cases: null array or invalid range (`start > end`) return -1. - `max(arr)` finds the maximum element in the entire array. - Returns -1 if array is empty. - Both methods use linear scan to compare and update max value. Signed-off-by: Somesh diwan <[email protected]>
1 parent d716764 commit d818eda

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Section9ArrayAB/Array IMP/Max.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ public static void main(String[] args) {
44
System.out.println(maxRange(arr, 1, 3));
55
}
66

7-
// work on edge cases here, like array being null
7+
// work on edge cases here, like an array being null.
88
static int maxRange(int[] arr, int start, int end) {
9-
109
if (start > end) {
1110
return -1;
1211
}
13-
1412
if (arr == null) {
1513
return -1;
1614
}

0 commit comments

Comments
 (0)