From f63261a4324a535b088eabbe791ef0a402545de6 Mon Sep 17 00:00:00 2001 From: amin Date: Thu, 27 Jun 2024 04:26:32 +0100 Subject: [PATCH] docs: adding subject and main --- .../maximal-square/ExerciseRunner.java | 27 +++++++++ .../java/checkpoints/maximal-square/README.md | 60 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 subjects/java/checkpoints/maximal-square/ExerciseRunner.java create mode 100644 subjects/java/checkpoints/maximal-square/README.md diff --git a/subjects/java/checkpoints/maximal-square/ExerciseRunner.java b/subjects/java/checkpoints/maximal-square/ExerciseRunner.java new file mode 100644 index 000000000..821bad8d5 --- /dev/null +++ b/subjects/java/checkpoints/maximal-square/ExerciseRunner.java @@ -0,0 +1,27 @@ +public class ExerciseRunner { + public static void main(String[] args) { + MaximalSquare finder = new MaximalSquare(); + + // Test case 1 + char[][] matrix1 = { + {'1', '0', '1', '0', '0'}, + {'1', '0', '1', '1', '1'}, + {'1', '1', '1', '1', '1'}, + {'1', '0', '0', '1', '0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix1)); // Expected output: 4 + + // Test case 2 + char[][] matrix2 = { + {'0', '1'}, + {'1', '0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix2)); // Expected output: 1 + + // Test case 3 + char[][] matrix3 = { + {'0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix3)); // Expected output: 0 + } +} \ No newline at end of file diff --git a/subjects/java/checkpoints/maximal-square/README.md b/subjects/java/checkpoints/maximal-square/README.md new file mode 100644 index 000000000..f25bca4b9 --- /dev/null +++ b/subjects/java/checkpoints/maximal-square/README.md @@ -0,0 +1,60 @@ +## Maximal Square + +### Instructions + +Create a class `MaximalSquare` that provides a method to find the area of the largest square containing only 1's in a given 2D binary matrix. + +### Expected Class + +```java +public class MaximalSquare { + public int maximalSquare(char[][] matrix) { + // Implementation to find the area of the largest square containing only 1's + } +} +``` + +### Usage + +Here is a possible `ExerciseRunner.java` to test your class: + +```java +public class ExerciseRunner { + public static void main(String[] args) { + MaximalSquare finder = new MaximalSquare(); + + // Test case 1 + char[][] matrix1 = { + {'1', '0', '1', '0', '0'}, + {'1', '0', '1', '1', '1'}, + {'1', '1', '1', '1', '1'}, + {'1', '0', '0', '1', '0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix1)); // Expected output: 4 + + // Test case 2 + char[][] matrix2 = { + {'0', '1'}, + {'1', '0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix2)); // Expected output: 1 + + // Test case 3 + char[][] matrix3 = { + {'0'} + }; + System.out.println("Maximal square area: " + finder.maximalSquare(matrix3)); // Expected output: 0 + } +} +``` + +### Expected Output + +```shell +$ javac *.java -d build +$ java -cp build ExerciseRunner +Maximal square area: 4 +Maximal square area: 1 +Maximal square area: 0 +$ +``` \ No newline at end of file