mirror of https://github.com/01-edu/public.git
amin
5 months ago
committed by
zanninso
2 changed files with 70 additions and 0 deletions
@ -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
|
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
## Steady Sequence |
||||
|
||||
### Instructions |
||||
|
||||
Create a class `SteadySequence` that provides a method to find the length of the longest consecutive elements sequence in an unsorted array of integers. |
||||
|
||||
### 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…
Reference in new issue