feat: remove CalculateMaxOfMin as it is implemented incorrectly

This commit is contained in:
vil02 2024-03-17 21:05:54 +01:00
parent 192427a5d2
commit d91b004bb5
2 changed files with 0 additions and 99 deletions

View File

@ -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
*/

View File

@ -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);
}
}