Skip to content

Commit a2e0e86

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank]: warmup: Mini-Max Sum. Better sample data.
1 parent c15c753 commit a2e0e86

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/hackerrank/warmup/mini_max_sum.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ pub fn mini_max_sum(arr: &[i32]) -> String {
55
panic!("Empty input");
66
}
77

8-
let mut tsum = 0;
9-
let mut tmin: i32 = arr[0];
10-
let mut tmax: i32 = arr[1];
8+
let mut tsum: i64 = 0;
9+
let mut tmin: i64 = arr[0].into();
10+
let mut tmax: i64 = arr[1].into();
11+
let mut tvalue: i64;
1112

1213
for value in arr.iter() {
13-
tsum += *value;
14+
tvalue = *value as i64;
15+
tsum += tvalue;
1416

15-
if *value < tmin {
16-
tmin = *value;
17+
if tvalue < tmin {
18+
tmin = tvalue;
1719
}
1820

19-
if *value > tmax {
20-
tmax = *value;
21+
if tvalue > tmax {
22+
tmax = tvalue;
2123
}
2224
}
2325

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
[
2-
{"input": [1, 2, 3, 4, 5], "expected": "10 14"},
3-
{"input": [5, 4, 3, 2, 1], "expected": "10 14"}
2+
{
3+
"title": "Sample",
4+
"input": [1, 2, 3, 4, 5],
5+
"expected": "10 14"
6+
},
7+
{
8+
"title": "Reversed Sample",
9+
"input": [5, 4, 3, 2, 1],
10+
"expected": "10 14"
11+
},
12+
{
13+
"title": "Test case 0",
14+
"input": [256741038, 623958417, 467905213, 714532089, 938071625],
15+
"expected": "2063136757 2744467344"
16+
}
417
]

tests/hackerrank/warmup/mini_max_sum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ mod tests {
1212
#[derive(Debug, Deserialize)]
1313
struct MiniMaxSumTest {
1414
input: Vec<i32>,
15-
expected: String
15+
expected: String,
16+
title: String
1617
}
1718

1819
static TEST_DATA: Lazy<Vec<MiniMaxSumTest>> =

0 commit comments

Comments
 (0)