aboutsummaryrefslogtreecommitdiff
path: root/challenge-080/duncan-c-white/README
blob: 425057dfc677263f3e002cc932a459cc79f856e0 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
Task 1: "Smallest Positive Number

You are given unsorted list of integers @N.

Write a script to find out the smallest positive number missing.
Example 1:

Input: @N = (5, 2, -2, 0)
Output: 1

Example 2:

Input: @N = (1, 8, -1)
Output: 2

Example 3:

Input: @N = (2, 0, -1)
Output: 1
"

My notes: ok. very straightforward.  Is it worth forming a set of values
for more efficient "is 1 a member?"  "is 2 a member?" etc? probably:-)


Task 2: "Count Candies

You are given rankings of @N candidates.

Write a script to find out the total candies needed for all candidates. You are asked to follow the rules below:
a) You must given at least one candy to each candidate.
b) Candidate with higher ranking get more candies than their mmediate neighbors on either side.
Example 1:

Input: @N = (1, 2, 2)

Explanation:

Applying rule #a, each candidate will get one candy. So total candies
needed so far 3. Now applying rule #b, the first candidate do not get any
more candy as its rank is lower than it's neighbours. The second candidate
gets one more candy as it's ranking is higher than it's neighbour. Finally
the third candidate do not get any extra candy as it's ranking is not
higher than neighbour. Therefore total candies required is 4.

Output: 4

Example 2:

Input: @N = (1, 4, 3, 2)

Explanation:

Applying rule #a, each candidate will get one candy. So total candies
needed so far 4. Now applying rule #b, the first candidate do not get
any more candy as its rank is lower than it's neighbours. The second
candidate gets two more candies as it's ranking is higher than it's
both neighbour. The third candidate gets one more candy as it's ranking
is higher than it's neighbour. Finally the fourth candidate do not get
any extra candy as it's ranking is not higher than neighbour. Therefore
total candies required is 7.

Output: 7
"

My notes: those rules could have written more clearly, but the examples
clarify that the "neighbours" are linear, not in a ring, so the two
end people's rankings each have only one neighbour to check.  Each person
gets between 1..3 candies.  Pretty simple.