Find a Character in the Growing Alphabet String

Quick Overview

Start from a and repeatedly append a copy with every letter shifted to its next alphabet character. Find a specified one-based position after enough operations.

Find a Character in the Growing Alphabet String

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Start with `word = "a"`. In each operation, make a new string by replacing every character of the current word with the next lowercase English letter, wrapping `z` to `a`. Append that new string to the unchanged current word. For example, applying the operation to `"c"` produces `"cd"`, while applying it to `"zb"` produces `"zbac"`. Given the positive integer `k`, return the `k`-th character after enough operations have been performed for the word to contain at least `k` characters. Positions are numbered starting from 1. ```cpp class Solution { public: char kthCharacter(int k); }; ``` ### Examples **Example 1:** ```text Input: k = 3 Output: "b" Explanation: The first two operations produce "ab" and then "abbc". Its third character is b. ``` **Example 2:** ```text Input: k = 8 Output: "d" Explanation: After three operations the word is "abbcbccd", whose eighth character is d. ``` ### Constraints - `1 <= k <= 500`. ### Clarifying Questions - Is `k` zero-based? No. The first character corresponds to `k = 1`. - Does the operation replace the current word? No. Keep it as the prefix and append its shifted copy. - Which characters generate the appended part? The characters present at the start of that operation. - Can later operations change the answer once position `k` exists? No. They only append characters. ### What a Strong Answer Covers - Applies the stated alphabet transformation and append order exactly. - Handles the first position and positions at the end of an operation's result. - Returns one character using the original API. ```hint Work within the given bound The bound of 500 permits constructing enough of the word directly. During an operation, transform only the characters that belonged to the word before that operation began. ```

Overview: Start from a and repeatedly append a copy with every letter shifted to its next alphabet character. Find a specified one-based position after enough operations.

Amazon logo
Amazon
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start with word = "a". In each operation, make a new string by replacing every character of the current word with the next lowercase English letter, wrapping z to a. Append that new string to the unchanged current word.

For example, applying the operation to "c" produces "cd", while applying it to "zb" produces "zbac".

Given the positive integer k, return the k-th character after enough operations have been performed for the word to contain at least k characters. Positions are numbered starting from 1.

class Solution {
public:
    char kthCharacter(int k);
};

Examples

Example 1:

Input: k = 3
Output: "b"
Explanation: The first two operations produce "ab" and then "abbc". Its third character is b.

Example 2:

Input: k = 8
Output: "d"
Explanation: After three operations the word is "abbcbccd", whose eighth character is d.

Constraints

  • 1 <= k <= 500 .

Clarifying Questions Guidance

  • Is k zero-based? No. The first character corresponds to k = 1 .
  • Does the operation replace the current word? No. Keep it as the prefix and append its shifted copy.
  • Which characters generate the appended part? The characters present at the start of that operation.
  • Can later operations change the answer once position k exists? No. They only append characters.

What a Strong Answer Covers Guidance

  • Applies the stated alphabet transformation and append order exactly.
  • Handles the first position and positions at the end of an operation's result.
  • Returns one character using the original API.