Crates.io | between-us |
lib.rs | between-us |
version | 1.0.0 |
source | src |
created_at | 2021-11-08 08:52:36.572855 |
updated_at | 2021-11-08 08:52:36.572855 |
description | Finds two most distant smaller and bigger numbers. |
homepage | |
repository | https://codeberg.org/ino/rusty-algos/src/branch/master/problems/between-us |
max_upload_size | |
id | 478423 |
size | 5,621 |
Far across the distance, And spaces, between us 🎵
Finds the maximmum right - left
, such that list[right] > list[left]
.
Time Complexity : O(n)
(2 traversals)
Space Complexity : O(n)
(1 extra list)
The find_distance
function takes a ref to an array or a vector as a paramaeter, and finds the maximum distance of two such elements.
It returns an Option<usize>
type as a result, because two such numbers that satisfy the condition might not exist. In that case, it returns None
.
Quick Start:
use between_us::interface::find_distance;
fn main() {
let list = [5, 3, 7, 1, 6, 8, 4];
let result = find_distance(&list);
println!("{:?}", result);
// Output: Some(5)
}