Problem · Array

Evaluate a Blackjack Hand

Learn this problem
EasyGoldman Sachs logoGoldman SachsFULLTIMEONSITE INTERVIEW

Problem statement

Given a blackjack hand in cards, return whether the cards can total exactly 21.

  • Cards 2 through 10 use their numeric values.
  • J, Q, and K each count as 10.
  • Each A may independently count as 1 or 11.

The hand may contain any positive number of cards.

Function

isBlackjack(cards: String[]) → boolean

Examples

Example 1

cards = ["A","K"]return = true

The Ace counts as 11, giving 21.

Example 2

cards = ["K","Q"]return = false

The total is 20.

Constraints

  • 1 <= cards.length <= 52
  • Every card is one of A, 2 through 10, J, Q, or K.

More Goldman Sachs problems

drafts saved locally
public boolean isBlackjack(String[] cards) {
  // write your code here
}
cards["A","K"]
expectedtrue
checking account