Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/hackerrank/warmup/mini_max_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ pub fn mini_max_sum(arr: &[i32]) -> String {
panic!("Empty input");
}

let mut tsum = 0;
let mut tmin: i32 = arr[0];
let mut tmax: i32 = arr[1];
let mut tsum: i64 = 0;
let mut tmin: i64 = arr[0].into();
let mut tmax: i64 = arr[1].into();
let mut tvalue: i64;

for value in arr.iter() {
tsum += *value;
tvalue = *value as i64;
tsum += tvalue;

if *value < tmin {
tmin = *value;
if tvalue < tmin {
tmin = tvalue;
}

if *value > tmax {
tmax = *value;
if tvalue > tmax {
tmax = tvalue;
}
}

Expand Down
17 changes: 15 additions & 2 deletions tests/data/hackerrank/warmup/mini_max_sum.testcases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{"input": [1, 2, 3, 4, 5], "expected": "10 14"},
{"input": [5, 4, 3, 2, 1], "expected": "10 14"}
{
"title": "Sample",
"input": [1, 2, 3, 4, 5],
"expected": "10 14"
},
{
"title": "Reversed Sample",
"input": [5, 4, 3, 2, 1],
"expected": "10 14"
},
{
"title": "Test case 0",
"input": [256741038, 623958417, 467905213, 714532089, 938071625],
"expected": "2063136757 2744467344"
}
]
3 changes: 2 additions & 1 deletion tests/hackerrank/warmup/mini_max_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ mod tests {
#[derive(Debug, Deserialize)]
struct MiniMaxSumTest {
input: Vec<i32>,
expected: String
expected: String,
title: String
}

static TEST_DATA: Lazy<Vec<MiniMaxSumTest>> =
Expand Down
4 changes: 2 additions & 2 deletions tests/hackerrank/warmup/staircase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ mod tests {
use super::*;

#[derive(Debug, Deserialize)]
struct AveryBigSumTestCase {
struct StaircaseTestCase {
input: i32,
expected: String
}

static TEST_DATA: Lazy<Vec<AveryBigSumTestCase>> =
static TEST_DATA: Lazy<Vec<StaircaseTestCase>> =
Lazy::new(|| load_json("tests/data/hackerrank/warmup/staircase.testcases.json"));

#[test]
Expand Down
Loading