DSAMaster Logo
DSAMaster
BackmediumStrings

Reverse Character Groups

Problem Description

Given a string of digits and letters, reverse each group of 3 characters. If a group has less than 3 characters, reverse the entire string.

Example 1
Input
abcdef
Output
cbafed

Explanation: Reversing each group of 3 characters: 'abc' becomes 'cba' and 'def' becomes 'fed', resulting in 'cbafed'

Example 2
Input
abcdefghi
Output
cbadefihg

Explanation: Reversing each group of 3 characters: 'abc' becomes 'cba', 'def' becomes 'fed', and 'ghi' becomes 'ihg', resulting in 'cbadefihg'

Example 3
Input
ab
Output
ba

Explanation: Since the label length is less than 3, the entire label is reversed, resulting in 'ba'

Constraints

  • Input string should be a unique alphanumeric identifier.
  • The length of the input string should be between 1 and 100.
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute