diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..03466cf --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,35 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, +# surfacing known-vulnerable versions of the packages declared or updated in the PR. +# Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable +# packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement +name: 'Dependency Review' +on: + pull_request: + branches: [ 'main' ] + +permissions: + contents: read + pull-requests: write + security-events: write + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout repository' + uses: actions/checkout@v4 + + - name: 'Dependency Review' + uses: actions/dependency-review-action@v4 + with: + comment-summary-in-pr: always + fail-on-severity: moderate + vulnerability-check: true + deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later + retry-on-snapshot-warnings: true + show-openssf-scorecard: true \ No newline at end of file diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0a23fb3..52608ce 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -13,7 +13,7 @@ on: branches: [ "main" ] jobs: - build: + maven-build: runs-on: ubuntu-latest permissions: @@ -25,7 +25,9 @@ jobs: steps: - - uses: actions/checkout@v4 + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: @@ -37,4 +39,10 @@ jobs: run: mvn -B clean verify --file pom.xml - name: Run Tests and Code-Coverage - run: mvn jacoco:prepare-agent clean test jacoco:report --file pom.xml \ No newline at end of file + run: mvn jacoco:prepare-agent clean test jacoco:report --file pom.xml + + - name: Submit Dependency Snapshot + uses: advanced-security/maven-dependency-submission-action@v4 + + # - name: Release source and test archives + # run: mvn -B clean verify --file pom.xml -Prelease \ No newline at end of file diff --git a/pom.xml b/pom.xml index 128853d..b898a86 100644 --- a/pom.xml +++ b/pom.xml @@ -167,6 +167,9 @@ ${project.build.sourceEncoding} brief true + + *com.shortthirdman.quickstart.common.* + 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