Skip to main content
Back to problems
Leetcode
Medium
Strings
Simulation
Bit Manipulation
Find the K-th Character in String Game I

Determine the character at position kk after repeatedly applying a simple string-growth rule.

Acceptance 100%
Problem Statement

Problem

You are given an initial string and a rule that grows the string in discrete rounds. In each round, the current string is transformed by appending a derived copy of itself according to the game rules.

Your task is to return the character that appears at 1-indexed position kk after the game has been played for enough rounds to make that position exist.

The exact transformation is simple enough that the answer can be reasoned about without building the entire final string.

Notes

  • Positions are 1-indexed.
  • The final string can become very large, so an efficient approach is expected.
  • The problem is about identifying the character at a specific position after repeated deterministic growth.

Input Format

  • An integer kk.
  • The initial game rule is implied by the problem statement.

You may assume the requested position is valid for the generated string.

Output Format

  • Return the single character at position kk in the generated string.

Constraints

  • 1k1 \le k is valid for the generated string.
  • The final string may be too large to construct explicitly.
  • Use O(1)O(1) or near-O(logk)O(\log k) extra space if possible.
Examples
Sample cases returned by the problem API.

Example 1

Input

k = 5

Output

b

Explanation

Using the game's deterministic growth rule, the character at position 5 can be traced back to the source segment and is '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.