Unit digit of power and deck of cards sum
Filed under HSBC
Free read 1 of 3Use modular exponentiation: (x^y) % 10. The cycle of unit digits repeats every 4 powers.
The question
Calculate the unit digit of x^y and find the total sum of values in a deck of cards.
Constraints
- x, y are non-negative integers
- Card values are standard (J=11, Q=12, K=13, A=1)
- Handle large y using modular exponentiation
Examples
- Input
- x=2, y=4
- Output
- 6
- Why
- 2^4 = 16, unit digit is 6.
Approach
Use modular exponentiation: (x^y) % 10. The cycle of unit digits repeats every 4 powers.
Map card faces to integer values and sum them up using a simple loop or reduction.
Handle y=0 (result 1) and empty card decks.
Tips
- What they are testing: Tests modular arithmetic properties and basic data aggregation.
- Common mistake: Calculating the full value of x^y instead of using (x^y) % 10.
Related HSBC questions
Collected from public candidate posts and coding forums. Updated Nov 2026.