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
//! Two Sum (Map Version, Generic, Hashable)
//!
//! Finds indices of the two numbers in the slice that add up to the target, using a map for O(n) performance.
//!
//! # Type Parameters
//! * `T`: The element type. Must implement `Copy` + `Eq` + `Hash` + `std::ops::Sub<Output = T>`.
//!
//! # Arguments
//! * `slice` - The slice to search.
//! * `target` - The target sum.
//!
//! # Returns
//! * `Option<(usize, usize)>` - Indices of the two elements, or None if not found.
//!
//! # Example
//! ```rust
//! use pofk_algorithm::set_algorithms::two_sum_map::two_sum_map;
//! let arr = [2, 7, 11, 15];
//! assert_eq!(two_sum_map(&arr, 9), Some((0, 1)));
//! assert_eq!(two_sum_map(&arr, 26), Some((2, 3)));
//! assert_eq!(two_sum_map(&arr, 100), None);
//! ```
use HashMap;