FastPrepBlackjack Hand Score
Problems/Blackjack Hand Score

Blackjack Hand Score

Zillow logoZillow● EasyFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from 2012 to 2016. One report places it in a phone interview, one in a 30-minute first-round interview and one in an onsite. A fourth report had phone rounds and then an onsite, and lists a Blackjack game among its topics without saying which round had it or what was asked. Three reports give a software engineer job title with no sign of an internship. The fourth came through a career fair and does not say whether the job was an internship or full-time. No report gives a level. The task was to score a Blackjack hand. In the onsite, the candidate got a Hand class holding a list of cards and had to fill in its score method. The phone interview report gave three example hands. They show an ace counting as 1 or 11 and a jack as 10, and that the score is the highest total that stays at or under 21, or the lowest total when every choice goes over 21.

The reports do not say how cards are written beyond those example hands, how much a queen, a king or a ten is worth, or how many cards a hand can hold. Here each card is a text value such as "A", "10" or "K" without a suit. A ten, a queen and a king are each worth 10, like a jack. A hand has 1 to 100 cards and is passed to a function as a list, not held in a Hand class. The editorial also covers a Hand object that keeps its score up to date as cards are added.

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

In Blackjack, each card in a hand is worth points:

  • Cards "2" through "10" are worth their number.
  • "J", "Q" and "K" are worth 10 each.
  • Each "A" (ace) is worth either 1 or 11. You choose the value for each ace separately.

Given the cards of a hand as cards, return the hand's score. The score is the largest total that is at most 21. If every possible total is over 21, the score is the smallest total.

Function

getScore(cards: String[]) → int

Examples

Example 1

cards = ["A","A","J"]return = 12

With both aces worth 1, the total is 1 + 1 + 10 = 12. Making one ace worth 11 gives 22, which is over 21. So the score is 12.

Example 2

cards = ["J","J","A","2"]return = 23

The two jacks and the 2 already add up to 22. Even with the ace worth 1, the total is 23. Every total is over 21, so the score is the smallest one, 23.

Example 3

cards = ["A","2"]return = 13

With the ace worth 11, the total is 13. With the ace worth 1, it is 3. Both are at most 21, and 13 is the larger one.

Example 4

cards = ["10","9","A","A"]return = 21

10 + 9 = 19. With both aces worth 1, the total is 21. Making any ace worth 11 gives at least 31, so the score is 21.

Example 5

cards = ["K","Q","5"]return = 25

There is no ace, so the only total is 10 + 10 + 5 = 25. It is over 21, but it is the smallest total, so the score is 25.

Constraints

  • 1 <= cards.length <= 100
  • Each cards[i] is one of "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q" or "K".

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TableOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • First Unique Character in a StringOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
  • First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014
  • Find the Four Missing Numbers in a FileOA · PHONE SCREEN · Seen Feb 2014

Similar questions at other companies

  • Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
  • Can Place FlowersAgoda · PHONE SCREENAgoda interview questions
  • Maximum Later Checkpoint Altitude GainYellow.ai · PHONE SCREEN
  • Assign CookiesAmazon · PHONE SCREEN
  • Maximum Profit with Exactly One Stock TransactionRetool · PHONE SCREEN · ONSITE INTERVIEWRetool interview questions
  • Best Time to Buy and Sell Stock IIGroww · ONSITE INTERVIEW
  • Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
  • Cheapest Round TripUber · ONSITE INTERVIEWUber interview questions
  • Best Time to Buy and Sell Stock IIPoint72 · PHONE SCREENPoint72 interview questions
  • Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int getScore(String[] cards) {
        // Write your code here.
    }
}
Checking account…