Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-2863 Markdown Steady Sequence Exercise #2612

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions subjects/java/checkpoints/steady-sequence/ExerciseRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class ExerciseRunner {
public static void main(String[] args) {
SteadySequence finder = new SteadySequence();

// Test case 1
int[] nums1 = {100, 4, 200, 1, 3, 2};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums1)); // Expected output: 4

// Test case 2
int[] nums2 = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums2)); // Expected output: 9

// Test case 3
int[] nums3 = {1, 2, 0, 1};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums3)); // Expected output: 3
}
}
53 changes: 53 additions & 0 deletions subjects/java/checkpoints/steady-sequence/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Steady Sequence

### Instructions

Create a class named `SteadySequence` that includes a method to determine the length of the longest consecutive sequence in an unsorted array of integers. The "longest consecutive sequence" refers to the sequence with the longest stretch of elements that increase strictly by 1. The elements of this sequence may appear in any order within the array.

nprimo marked this conversation as resolved.
Show resolved Hide resolved
### Expected Class

```java
import java.util.HashSet;
import java.util.Set;

public class SteadySequence {
public int longestSequence(int[] nums) {
// Implementation to find the length of the longest consecutive elements sequence
}
}
```

### Usage

Here is a possible `ExerciseRunner.java` to test your class:

```java
public class ExerciseRunner {
public static void main(String[] args) {
SteadySequence finder = new SteadySequence();

// Test case 1
int[] nums1 = {100, 4, 200, 1, 3, 2};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums1)); // Expected output: 4

// Test case 2
int[] nums2 = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums2)); // Expected output: 9

// Test case 3
int[] nums3 = {1, 2, 0, 1};
System.out.println("Longest consecutive sequence length: " + finder.longestSequence(nums3)); // Expected output: 3
}
}
```

### Expected Output

```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Longest consecutive sequence length: 4
Longest consecutive sequence length: 9
Longest consecutive sequence length: 3
$
```
Loading