As reported: Visa Staff Software Engineer (backend, Java / Spring Boot), round 1 coding (2026): one question, LeetCode Hand of Straights. An
O(n log n)approach was not enough — the interviewer insisted onO(n).
hand[i] is the value of the i-th card. Decide whether the cards can be rearranged into groups of exactly groupSize cards, each group made of groupSize consecutive values.
This is LeetCode 846 — Hand of Straights.
Example
hand = [1,2,3,6,2,3,4,7,8], groupSize = 3 -> true ([1,2,3], [2,3,4], [6,7,8])
hand = [1,2,3,4,5], groupSize = 4 -> false
Constraints: 1 ≤ hand.length ≤ 10^4; 0 ≤ hand[i] ≤ 10^9; 1 ≤ groupSize ≤ hand.length. Target: O(n) time.
Code runner format: one JSON value per line: hand, then groupSize. Implement isNStraightHand(hand, groupSize); the harness prints true or false.