Start learning free

LESSON 70 OF 505 · STRINGS - CHALLENGES

Creating IDs in Scala

Practice

A website creates a user ID from each person's name: the first 2 letters of the first name, followed by the last 3 letters of the last name.

Given the first name first and the last name last, return the ID.

 

Example 1:

Input: first = "John", last = "Smith"
Output: "Joith"
Explanation: "Jo" are the first 2 letters of "John" and "ith" are the last 3 letters of "Smith".

Example 2:

Input: first = "Jo", last = "Doe"
Output: "JoDoe"
Explanation: "Jo" has exactly 2 letters and "Doe" exactly 3, so both names are used whole.

Example 3:

Input: first = "ada", last = "Lovelace"
Output: "adace"
Explanation: The letters keep their case: the ID doesn't change any letter to upper or lower case.

 

Constraints:

  • first has at least 2 letters and last has at least 3 letters.
  • Both names are made of English letters only, lowercase or uppercase.
STEP 1 OF 1
    Ctrl + Enter to check

    Creating Ids in Scala

    Keep going with Scala500+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free