junit.jupiter.extensions.autodetection.enabled = true
diff --git a/src/main/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlices.java b/src/main/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlices.java
new file mode 100644
index 0000000..326dc42
--- /dev/null
+++ b/src/main/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlices.java
@@ -0,0 +1,60 @@
+package com.shortthirdman.quickstart.codesignal;
+
+import java.util.Arrays;
+
+/**
+ * An integer M and a non-empty array A consisting of N non-negative integers are given.
+ * All integers in array A are less than or equal to M
.
+ * A pair of integers (P, Q)
, such that 0 ≤ P ≤ Q < N
, is called a slice of array A
.
+ *
+ * The slice consists of the elements A[P], A[P + 1], ..., A[Q]. A distinct slice is a slice consisting of only unique numbers. That is, no individual number occurs more than once in the slice.
+ *
+ * For example, consider integer M = 6 and array A such that:
+ *
+ * A[0] = 3
+ * A[1] = 4
+ * A[2] = 5
+ * A[3] = 5
+ * A[4] = 2
+ *
+ * There are exactly nine distinct slices:
+ * (0, 0), (0, 1), (0, 2), (1, 1), (1, 2), (2, 2), (3, 3), (3, 4) and (4, 4).
+ *
+ * The goal is to calculate the number of distinct slices.
+ *
+ * @author ShortThirdMan
+ */
+public class CountDistinctSlices {
+
+ /**
+ * Given an integer M and a non-empty array A consisting of N integers, returns the number of distinct slices.
+ *
+ * If the number of distinct slices is greater than 1,000,000,000, the function should return 1,000,000,000.
+ * @param M integer
+ * @param A non-empty array
+ * @return number of distinct slices
+ */
+ public int calculateDistinctSlices(int M, int[] A) {
+ int N = A.length;
+ if (N < 1 || N > 100000) {
+ throw new IllegalArgumentException("Array length should be between 1 and 100000");
+ }
+
+ if (M < 0 || M > 100000) {
+ throw new IllegalArgumentException("Integer M should be between 0 and 100000");
+ }
+
+ boolean isNotInRange = Arrays.stream(A).boxed().anyMatch(n -> n < 0 || n > M);
+ if (isNotInRange) {
+ throw new IllegalArgumentException("Each element in array should be between 0 and " + M);
+ }
+
+ int distinctSlices = 0;
+
+ if (distinctSlices > 1_000_000_000) {
+ return 1_000_000_000;
+ }
+
+ return distinctSlices;
+ }
+}
diff --git a/src/main/java/com/shortthirdman/quickstart/codesignal/EquiLeader.java b/src/main/java/com/shortthirdman/quickstart/codesignal/EquiLeader.java
new file mode 100644
index 0000000..8d22cd5
--- /dev/null
+++ b/src/main/java/com/shortthirdman/quickstart/codesignal/EquiLeader.java
@@ -0,0 +1,6 @@
+package com.shortthirdman.quickstart.codesignal;
+
+
+public class EquiLeader {
+
+}
diff --git a/src/test/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlicesTest.java b/src/test/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlicesTest.java
new file mode 100644
index 0000000..31c3889
--- /dev/null
+++ b/src/test/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlicesTest.java
@@ -0,0 +1,15 @@
+package com.shortthirdman.quickstart.codesignal;
+
+import org.junit.jupiter.api.BeforeEach;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CountDistinctSlicesTest {
+
+ CountDistinctSlices app;
+
+ @BeforeEach
+ void setUp() {
+ app = new CountDistinctSlices();
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/shortthirdman/quickstart/codesignal/EquiLeaderTest.java b/src/test/java/com/shortthirdman/quickstart/codesignal/EquiLeaderTest.java
new file mode 100644
index 0000000..3177211
--- /dev/null
+++ b/src/test/java/com/shortthirdman/quickstart/codesignal/EquiLeaderTest.java
@@ -0,0 +1,20 @@
+package com.shortthirdman.quickstart.codesignal;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class EquiLeaderTest {
+
+ EquiLeader app;
+
+ @BeforeEach
+ void setUp() {
+ app = new EquiLeader();
+ }
+
+ @AfterEach
+ void tearDown() {
+ }
+}
\ No newline at end of file