BackmediumStrings Atlassian

Package Label Generator Solution

Problem Statement

Given a package label, reverse each group of 3 characters. If a group has less than 3 characters, reverse the entire label. If the label length is a multiple of 3, the last group should also be in reverse.

Example 1
Input
abcdef
Output
fedcba

Explanation: Step-by-step: 1. Split the input string into groups of 3 characters: ['abc', 'def']. 2. Reverse each group: ['cba', 'fed']. 3. Concatenate the reversed groups: 'fedcba'.

Example 2
Input
abcdefgh
Output
dcba

Explanation: Step-by-step: 1. Split the input string into groups of 3 characters: ['abc', 'def', 'ghi', 'cde']. 2. Reverse each group: ['cba', 'fed', 'ihg', 'dec']. 3. Since the last group 'cde' has less than 3 characters, reverse the entire label: 'dcba'.

Constraints

  • Input string should be a unique alphanumeric identifier.
  • The length of the input string should be between 1 and 100.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free