โ† HSBC questions

Unit digit of power and deck of cards sum

Filed under HSBC

Free read 1 of 3

Use 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

  1. Use modular exponentiation: (x^y) % 10. The cycle of unit digits repeats every 4 powers.

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.