Problem · String
K-th Character in an Infinite String
Learn this problemProblem statement
Build an infinite string from non-empty strings s and t in numbered blocks:
- Append
sonce. - Append
ttwice. - Append
sthree times. - Append
tfour times. - Continue alternating strings while increasing the repetition count by one for each block.
Given a 1-indexed position k, return the character at that position.
Function
kthInfiniteCharacter(s: String, t: String, k: long) → charExamples
Example 1
s = "a"t = "bc"k = 4return = bThe beginning is abcbcaaabcbcbcbc.... Position 4 contains b.
Example 2
s = "ab"t = "x"k = 7return = aThe first three blocks are ab, xx, and ababab. Position 7 is the third character of the third block, which is a.
Constraints
1 <= s.length, t.length <= 100.1 <= k <= 10^16.
More Arcesium problems
- Ordered Payload ReleaseONSITE INTERVIEW · Seen Jul 2026
- Decode Numeric StringONSITE INTERVIEW · Seen Jun 2026
- Tree Ancestor QueriesONSITE INTERVIEW · Seen Jun 2026
- City Infection NumberOA · Seen Jul 2025
- Minimum Tunnel Crossing TimeOA · Seen Jul 2025
- Product of Subset MaximaOA · Seen Jul 2025
- Reconstruct the Root StreamOA · Seen Jul 2025
- Add DigitsOA · Seen Aug 2023