From d91b004bb544f6f3a093bd43f5fb647dfdcc52e3 Mon Sep 17 00:00:00 2001 From: vil02 Date: Sun, 17 Mar 2024 21:05:54 +0100 Subject: [PATCH] feat: remove `CalculateMaxOfMin` as it is implemented incorrectly --- .../stacks/CalculateMaxOfMin.java | 42 -------------- .../stacks/CalculateMaxOfMinTest.java | 57 ------------------- 2 files changed, 99 deletions(-) delete mode 100644 src/main/java/com/thealgorithms/stacks/CalculateMaxOfMin.java delete mode 100644 src/test/java/com/thealgorithms/stacks/CalculateMaxOfMinTest.java diff --git a/src/main/java/com/thealgorithms/stacks/CalculateMaxOfMin.java b/src/main/java/com/thealgorithms/stacks/CalculateMaxOfMin.java deleted file mode 100644 index 399b9efd..00000000 --- a/src/main/java/com/thealgorithms/stacks/CalculateMaxOfMin.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Author : Siddhant Swarup Mallick - * Github : https://github.com/siddhant2002 - */ - -/** - * Program description - Given an integer array. The task is to find the maximum of the minimum of - * the array - */ -package com.thealgorithms.stacks; - -import java.util.*; - -public class CalculateMaxOfMin { - - public static int calculateMaxOfMin(int[] a) { - int n = a.length; - int[] ans = new int[n]; - int[] arr2 = Arrays.copyOf(a, n); - Arrays.sort(arr2); - int maxNum = arr2[arr2.length - 1]; - ans[0] = maxNum; - int index = 1; - while (index != ans.length) { - int[] minimums = new int[n - index]; - for (int i = 0; i < n - index; i++) { - int[] windowArray = Arrays.copyOfRange(a, i, i + index + 1); - Arrays.sort(windowArray); - int minNum = windowArray[0]; - minimums[i] = minNum; - } - Arrays.sort(minimums); - ans[index] = minimums[minimums.length - 1]; - index += 1; - } - return ans[0]; - } -} -/** - * Given an integer array. The task is to find the maximum of the minimum of the - * given array - */ diff --git a/src/test/java/com/thealgorithms/stacks/CalculateMaxOfMinTest.java b/src/test/java/com/thealgorithms/stacks/CalculateMaxOfMinTest.java deleted file mode 100644 index 4cb1f48d..00000000 --- a/src/test/java/com/thealgorithms/stacks/CalculateMaxOfMinTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.thealgorithms.stacks; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -public class CalculateMaxOfMinTest { - - @Test - void testForOneElement() { - int[] a = {10, 20, 30, 50, 10, 70, 30}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(70, k); - } - - @Test - void testForTwoElements() { - int[] a = {5, 3, 2, 6, 3, 2, 6}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(6, k); - } - - @Test - void testForThreeElements() { - int[] a = {10, 10, 10, 10, 10, 10, 10}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(10, k); - } - - @Test - void testForFourElements() { - int[] a = {70, 60, 50, 40, 30, 20}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(70, k); - } - - @Test - void testForFiveElements() { - int[] a = {50}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(50, k); - } - - @Test - void testForSixElements() { - int[] a = {1, 4, 7, 9, 2, 4, 6}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(9, k); - } - - @Test - void testForSevenElements() { - int[] a = {-1, -5, -7, -9, -12, -14}; - int k = CalculateMaxOfMin.calculateMaxOfMin(a); - assertEquals(-1, k); - } -}