-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-minDiff.peml
58 lines (48 loc) · 1.39 KB
/
cw-minDiff.peml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/573/practice?workout_id=759
title: minDiff
external_id: ITSC1213_min_diff
is_public: true
experience: 20
language_list: Java
license.id: cc-sa-4.0
license.owner.email: [email protected]
license.owner.name: lcao2
tags.topics: array, loop
tags.style: coding problem
instructions:----------
This method takes an integer array as a parameter and returns the
minimum difference between adjacent values in the array. The difference between
two adjacent values in an array is defined as the second value minus the first
value. For example, if array stores the following sequence of values: {3,
5, 11, 4, 8}, the differences would be computed as 5 – 3 = 2, 11 - 5 = 6,
4 - 11 = -7, 8 - 4 = 4. Of these values, -7 is the smallest, so it would be
returned. If an array has less than 2 elements, the method should return 0.
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
public class ArrayProblem
{
___
}
----------
[assets.code.starter.files]
content:----------
public int minDiff(int[] nums)
{
___
}
----------
[assets.test.files]
format: text/csv-unquoted
pattern_actual: subject.minDiff({{nums}})
content:----------
nums,expected,description
"new int[] {3, 5, 11, 4, 8}",-7,example
"new int[]{}",0
"new int[]{17}",0
"new int[]{1, 3, 6, 12, 7}",-5
"new int[]{1, 2, 3, 5, 7}",1
"new int[]{3, 5, 4, 8, 11, 14}",-1
----------