FastPrepDetect a Straight Flush
Problems/Detect a Straight Flush

Detect a Straight Flush

Temu logoTemu● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Temu asked this in a second-round technical phone screen for a Java engineer role on its order team. The candidate got a hand of 5 to 52 playing cards, each written as a suit letter and then a rank. They had to decide whether some five of them make a straight flush: one suit and five ranks in a row. The ace may sit at the low end or the high end, but a straight may not run past the ace and start over.

The report did not say what the function should return, whether a card can show up twice, or what to do with a malformed card. We chose these. The answer is true or false. All cards in the hand are different, as if dealt from one deck. Every card string is well formed.

Our version is about 95% the same as the reported question.

You are given an array cards of playing cards from a standard 52-card deck. Each card is a string: its suit letter followed by its rank. For example, "CA" is the ace of clubs, "H10" is the 10 of hearts, "SK" is the king of spades and "D5" is the 5 of diamonds.

  • Suits: S (spades), H (hearts), C (clubs) and D (diamonds).
  • Ranks, from low to high: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K.

Return true if you can pick 5 of the cards that form a straight flush, and false otherwise. Five cards form a straight flush when both of these hold:

  1. All five cards have the same suit.
  2. Their ranks are five consecutive ranks.

The ace can be used as the lowest rank or as the highest rank, so A-2-3-4-5 and 10-J-Q-K-A are both straights. A straight cannot wrap around through the ace: Q-K-A-2-3 is not a straight.

Function

hasStraightFlush(cards: String[]) → boolean

Examples

Example 1

cards = ["S9","HK","HQ","C10","HA","HJ","H10"]return = true
  • The hearts are HK, HQ, HA, HJ and H10.
  • Their ranks are 10, J, Q, K and A, and the ace may count as the highest rank, so these five hearts form a straight flush.

Example 2

cards = ["SQ","SK","SA","S2","S3","D4"]return = false
  • The five spades have ranks Q, K, A, 2 and 3.
  • A straight cannot wrap around past the ace, so Q-K-A-2-3 is not a straight. No other suit has five cards, so the answer is false.

Example 3

cards = ["C5","D6","C7","C8","C9","CA","C4"]return = false
  • The ranks 5, 6, 7, 8 and 9 are consecutive, but D6 is a diamond, so they are not all one suit.
  • The clubs are 4, 5, 7, 8, 9 and A. They have no five consecutive ranks (6 and 3 are missing), so the answer is false.

Constraints

  • 5 <= cards.length <= 52
  • Each cards[i] is one suit letter (S, H, C or D) followed by one rank (A, 2 to 10, J, Q or K), so it has 2 or 3 characters.
  • All cards in cards are distinct.

More Temu interview questions

  • Next Taller Building to the RightPHONE SCREEN · Seen Nov 2026
  • SubsetsPHONE SCREEN · Seen Nov 2026
  • Spiral Order with ObstaclesPHONE SCREEN · Seen Oct 2026
  • Generate Spiral MatrixPHONE SCREEN · Seen Aug 2026
  • Merge Two Sorted Collections Without DuplicatesPHONE SCREEN · Seen Aug 2026
  • Spiral Matrix with ObstaclesONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Most Frequent NameAmazon · PHONE SCREEN
  • Words with Repeated AnagramsThe Voleon Group · PHONE SCREEN
  • Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
  • Product Keyword SearchTesco · PHONE SCREEN
  • Verify Words Sorted by a Custom AlphabetTrueFoundry · PHONE SCREEN
  • Character Frequencies Across Nested String ListsSnowflake · PHONE SCREENSnowflake interview questions
  • Neighboring Record IDsZipRecruiter · PHONE SCREENZipRecruiter interview questions
All Temu interview questionsSee Temu hiring insights
Saved
class Solution {
    public boolean hasStraightFlush(String[] cards) {
        // Write your code here.
    }
}
Checking account…