mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-11-09 22:08:58 +01:00
feat(challenges): add is-valid-array-subsequence
This commit is contained in:
parent
0df7b6620e
commit
c4b0e9e757
@ -55,7 +55,7 @@ See the `test` folder for examples of input/output.
|
||||
2
|
||||
```
|
||||
|
||||
### Example 1
|
||||
### Example 2
|
||||
|
||||
#### Input
|
||||
|
||||
|
52
challenges/is-valid-array-subsequence/README.md
Normal file
52
challenges/is-valid-array-subsequence/README.md
Normal file
@ -0,0 +1,52 @@
|
||||
# is-valid-array-subsequence
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 23 April 2022.
|
||||
|
||||
## Instructions
|
||||
|
||||
Given two non-empty arrays of integers, write a function that determines whether the second array is a subsequence of the first one.
|
||||
|
||||
A subsequence of an array is a set of numbers that aren't necessarily adjacent in the array but that are in the same order as they appear in the array. For instance, the numbers `[1, 3, 4]` form a subsequence of the array `[1, 2, 3, 4]`, and so do the numbers `[2, 4]`. Note that a single number in an array and the array itself are both valid subsequences of the array.
|
||||
|
||||
### Input
|
||||
|
||||
- **Line 1:** `array` Integers separated by spaces
|
||||
- **Line 2:** `sequence` Integers separated by spaces
|
||||
|
||||
### Output
|
||||
|
||||
The output should return `true` if the `sequence` is a subsequence of `array` and `false` otherwise.
|
||||
|
||||
## Examples
|
||||
|
||||
See the `test` folder for examples of input/output.
|
||||
|
||||
### Example 1
|
||||
|
||||
#### Input
|
||||
|
||||
```txt
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 10
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```txt
|
||||
true
|
||||
```
|
||||
|
||||
### Example 2
|
||||
|
||||
#### Input
|
||||
|
||||
```txt
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 25 6 -1 8 10 12
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```txt
|
||||
false
|
||||
```
|
2
challenges/is-valid-array-subsequence/test/1/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/1/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 10
|
1
challenges/is-valid-array-subsequence/test/1/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/1/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/10/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/10/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 25 6 -1 8 10 12
|
1
challenges/is-valid-array-subsequence/test/10/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/10/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/11/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/11/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
4 5 1 22 25 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/11/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/11/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/12/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/12/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 23 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/12/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/12/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/13/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/13/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 22 25 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/13/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/13/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/14/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/14/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 22 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/14/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/14/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/15/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/15/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 -1
|
1
challenges/is-valid-array-subsequence/test/15/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/15/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/16/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/16/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 -1 10
|
1
challenges/is-valid-array-subsequence/test/16/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/16/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/17/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/17/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 -2
|
1
challenges/is-valid-array-subsequence/test/17/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/17/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/18/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/18/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
26
|
1
challenges/is-valid-array-subsequence/test/18/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/18/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/19/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/19/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 25 22 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/19/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/19/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/2/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/2/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 25 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/2/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/2/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/20/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/20/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 26 22 8
|
1
challenges/is-valid-array-subsequence/test/20/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/20/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/21/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/21/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
1 1 6 1
|
||||
1 1 1 6
|
1
challenges/is-valid-array-subsequence/test/21/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/21/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/22/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/22/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 10 11 11 11 11
|
1
challenges/is-valid-array-subsequence/test/22/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/22/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/23/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/23/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 25 6 -1 8 10 10
|
1
challenges/is-valid-array-subsequence/test/23/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/23/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/24/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/24/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 -1 5
|
1
challenges/is-valid-array-subsequence/test/24/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/24/output.txt
Normal file
@ -0,0 +1 @@
|
||||
false
|
2
challenges/is-valid-array-subsequence/test/3/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/3/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 6 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/3/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/3/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/4/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/4/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
22 25 6
|
1
challenges/is-valid-array-subsequence/test/4/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/4/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/5/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/5/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
1 6 10
|
1
challenges/is-valid-array-subsequence/test/5/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/5/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/6/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/6/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 1 22 10
|
1
challenges/is-valid-array-subsequence/test/6/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/6/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/7/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/7/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
5 -1 8 10
|
1
challenges/is-valid-array-subsequence/test/7/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/7/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/8/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/8/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
5 1 22 25 6 -1 8 10
|
||||
25
|
1
challenges/is-valid-array-subsequence/test/8/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/8/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
2
challenges/is-valid-array-subsequence/test/9/input.txt
Normal file
2
challenges/is-valid-array-subsequence/test/9/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
1 1 1 1 1
|
||||
1 1 1
|
1
challenges/is-valid-array-subsequence/test/9/output.txt
Normal file
1
challenges/is-valid-array-subsequence/test/9/output.txt
Normal file
@ -0,0 +1 @@
|
||||
true
|
Loading…
Reference in New Issue
Block a user