← All problemsSign in

3794. Reverse String Prefix

LeetCodeTwo PointersStringOpen on judge ↗

You are given a string s and an integer k. Reverse the first k characters of s and return the resulting string. Example 1: Input: s = "abcd", k = 2 Output: "bacd" Explanation:​​​​​​​ The first k = 2 characters "ab" are reversed to "ba". The final resulting string is "bacd". Example 2: Input: s = "xyz", k = 3 Output: "zyx" Explanation: The first k = 3 characters "xyz" are reversed to "

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start