Trains the technique from
LeetCode 3614Process String with Special Operations IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tape starts empty. The string s is read left to right, one character at a time, and each character is an instruction:
'*' removes the last character of the tape, and does nothing when the tape is already empty;'#' appends a copy of the whole tape to itself, so the tape doubles in length;'%' reverses the tape.Return the character sitting at slot k of the finished tape, counting slots from 0. If the finished tape holds k characters or fewer, return "." instead.
Example 1
The tape reads "ab" after two letters, then doubling makes it "abab". Slot 3 of that tape holds "b".
Example 2
Reversing "ab" gives "ba", so slot 0 holds "b".
Example 3
The finished tape holds one character, so slot 1 is past its end and the answer is ".".
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def char_at_position(s: str, k: int) -> str:public char charAtPosition(String s, long k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.