Practice

Extract Country Code

2025/May/June·Variant 1
MEDIUMString Processing

A telephone number is input as a 13-character string. The first character is always '+', followed by a 2-digit country code (e.g. "+441234567890").

Extract the 2-digit country code and check its value:

  • Code "44" → output UK
  • Code "20" → output Egypt
  • Any other code → output Unknown

Input: A single 13-character string. Output: UK, Egypt, or Unknown.

Example:

Input:  +201234567890
Output: Egypt

Sample Test Cases

Test 1: UK country code
Inputs: +441234567890
Expected: UK
Test 2: Egypt country code
Inputs: +209876543210
Expected: Egypt
Test 3: Unknown country code
Inputs: +115555555555
Expected: Unknown

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started