-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new GitHub Action workflow for dependency review, new coding ch…
…allenge question created (partial)
- Loading branch information
1 parent
cf35351
commit 7a3207a
Showing
7 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>M</code>. | ||
* A pair of integers <code>(P, Q)</code>, such that <code>0 ≤ P ≤ Q < N</code>, is called a slice of array <code>A</code>. | ||
* <br></br> | ||
* 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. | ||
* <br></br> | ||
* For example, consider integer M = 6 and array A such that: | ||
* <pre> | ||
* A[0] = 3 | ||
* A[1] = 4 | ||
* A[2] = 5 | ||
* A[3] = 5 | ||
* A[4] = 2 | ||
* </pre> | ||
* There are exactly nine distinct slices: | ||
* <pre>(0, 0), (0, 1), (0, 2), (1, 1), (1, 2), (2, 2), (3, 3), (3, 4) and (4, 4).</pre> | ||
* | ||
* 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. | ||
* <br> | ||
* 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; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/shortthirdman/quickstart/codesignal/EquiLeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.shortthirdman.quickstart.codesignal; | ||
|
||
|
||
public class EquiLeader { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/shortthirdman/quickstart/codesignal/CountDistinctSlicesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/com/shortthirdman/quickstart/codesignal/EquiLeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
} | ||
} |