Skip to main content
Back to problems
Leetcode
Medium
Arrays
Bit Manipulation
Recursion
Math
Google
Meta
Find The K Th Character In String Game Ii

Determine the kk-th character in a string built through repeated expansion rules without constructing the full string.

Acceptance 100%
Problem Statement

Problem

You are given a starting string and a sequence of expansion rules that repeatedly transform it into a much longer string. Your task is to determine the character at position kk in the final string.

The final string can become extremely large, so a correct solution should avoid explicitly building the entire result when possible. Instead, reason about how positions map through each expansion step and trace the query position back through the transformations until the answer is found.

Goal

Return the character that appears at the 1-indexed position kk after all transformations have been applied.

Notes

  • The exact transformation details are encoded by the input for the platform problem.
  • The intended challenge is to locate a single character in a recursively defined generated string.
  • Efficient solutions usually work by following the ancestry of position kk through the construction process rather than simulating the full string.

Input Format

  • The input describes the generation rules for the string and a query index kk.
  • Assume the position kk is 1-indexed.
  • The generated string may be too large to materialize directly.

Output Format

  • Return a single character: the character located at position kk in the final generated string.

Constraints

  • The generated string may grow exponentially across steps.
  • kk is within the length of the final string.
  • An efficient solution should use sublinear extra space and avoid constructing the full string.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "a"
operations = ["ab", "bc"]
k = 2

Output

b

Explanation

After the first expansion, the string becomes "ab". The second expansion changes it according to the given rule set, and the character at position 2 is still 'b'.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.