Start learning free

LESSON 72 OF 505 · STRINGS - CHALLENGES

Repeat Last Char in Kotlin

Practice

Given a string s and a number n, return a new string made of the last character of s, written n times in a row.

 

Example 1:

Input: s = "banana", n = 3
Output: "aaa"
Explanation: The last character of "banana" is "a". Written 3 times, it gives "aaa".

Example 2:

Input: s = "Wow!", n = 2
Output: "!!"
Explanation: The last character can be any character: here it is the exclamation mark.

Example 3:

Input: s = "z", n = 1
Output: "z"
Explanation: A string of one character: its last character is "z", written once.

 

Constraints:

  • s has at least one character and doesn't start or end with a space.
  • s contains English letters, digits, spaces and punctuation.
  • n is a whole number from 1 to 10.
STEP 1 OF 1
    Ctrl + Enter to check

    Repeat Last Char in Kotlin

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