Hand of Straights
Medium Problems DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Binary Search Algorithm: How does binary search work, what are its variations, and what are its advantages and disadvantages compared to linear search?, Frequency Counting, Greedy Algorithm, Sorting, Hash Map, Heap/Priority Queue, space complexity, array, divide and conquer, iterative vs recursive, binary search, time complexity analysis.
Hands of Straights Problem Statement : Given an integer array hand representing cards in a hand and an integer groupSize, determine if the cards can be rearranged into groups where each group consists of exactly groupSize consecutive cards in increasing order. Input Specification : hand: An array of integers representing the cards (e.g., [1, 2, 3, 6, 2, 3, 4, 7, 8]). groupSize: An integer (e.g., 3). Output Specification : Return true if the cards can be rearranged into such groups, otherwise false (e.g., true for the above input, as groups can be [1,2,3], [2,3,4], [6,7,8]). Constraints : 1 <= hand.length <= 10^4 0 <= hand[i] <= 10^9 1 <= groupSize <= hand.length Sample Input : Sample Output : Difficulty Level : Medium Relevant Concepts : Frequency Counting Greedy Algorithm Sorting Hash Map