https://github.com/aliezzahn/trapping_rain_water
The problem involves calculating the amount of rainwater that can be trapped between the bars of an elevation map represented by a vector of non-negative integers.
https://github.com/aliezzahn/trapping_rain_water
Last synced: 3 months ago
JSON representation
The problem involves calculating the amount of rainwater that can be trapped between the bars of an elevation map represented by a vector of non-negative integers.
- Host: GitHub
- URL: https://github.com/aliezzahn/trapping_rain_water
- Owner: aliezzahn
- License: mit
- Created: 2025-02-24T11:40:42.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-24T11:44:58.000Z (3 months ago)
- Last Synced: 2025-02-24T12:36:22.583Z (3 months ago)
- Language: Rust
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Trapping Rain Water
The problem involves calculating the amount of rainwater that can be trapped between the bars of an elevation map represented by a vector of non-negative integers.
## Problem Description
Given an array `height` where each element represents the height of a bar, compute how much water can be trapped after raining.
## Solution
The solution uses a two-pointer approach to efficiently compute the trapped water in `O(n)` time and `O(1)` space.
## Usage
Add this crate to your `Cargo.toml`:
```toml
[dependencies]
trapping_rain_water = { git = "https://github.com/aliezzahn/trapping_rain_water.git" }
```Then, use the `trap` function in your code:
```rust
use trapping_rain_water::trap;fn main() {
let height = vec![0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1];
println!("Trapped water: {}", trap(height));
}
```## Running Tests
To run the tests, use the following command:
```bash
cargo test
```