846. Hand of Straights Medium
1/**
2 * [846] Hand of Straights
3 *
4 * Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.
5 * Given an integer array hand where hand[i] is the value written on the i^th card and an integer groupSize, return true if she can rearrange the cards, or false otherwise.
6 *
7 * Example 1:
8 *
9 * Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3
10 * Output: true
11 * Explanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]
12 *
13 * Example 2:
14 *
15 * Input: hand = [1,2,3,4,5], groupSize = 4
16 * Output: false
17 * Explanation: Alice's hand can not be rearranged into groups of 4.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= hand.length <= 10^4
23 * 0 <= hand[i] <= 10^9
24 * 1 <= groupSize <= hand.length
25 *
26 *
27 * Note: This question is the same as 1296: <a href="https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/" target="_blank">https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/</a>
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/hand-of-straights/
33// discuss: https://leetcode.com/problems/hand-of-straights/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn is_n_straight_hand(hand: Vec<i32>, group_size: i32) -> bool {
39 false
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_846() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.