1497. Check If Array Pairs Are Divisible by k Medium
1/**
2 * [1497] Check If Array Pairs Are Divisible by k
3 *
4 * Given an array of integers arr of even length n and an integer k.
5 * We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.
6 * Return true If you can find a way to do that or false otherwise.
7 *
8 * Example 1:
9 *
10 * Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5
11 * Output: true
12 * Explanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).
13 *
14 * Example 2:
15 *
16 * Input: arr = [1,2,3,4,5,6], k = 7
17 * Output: true
18 * Explanation: Pairs are (1,6),(2,5) and(3,4).
19 *
20 * Example 3:
21 *
22 * Input: arr = [1,2,3,4,5,6], k = 10
23 * Output: false
24 * Explanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.
25 *
26 *
27 * Constraints:
28 *
29 * arr.length == n
30 * 1 <= n <= 10^5
31 * n is even.
32 * -10^9 <= arr[i] <= 10^9
33 * 1 <= k <= 10^5
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/
39// discuss: https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn can_arrange(arr: Vec<i32>, k: i32) -> bool {
45 false
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1497() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.