# Problem Description
This is a sequence transformation problem where:
- Given an initial sequence and a pointer position
- The goal is to transform the sequence following specific rules about moving elements
- The transformation involves moving certain elements based on the pointer position
- Uses 1-based indexing for the pointer position

# Visual Facts
1. Example 1 shows:
   - Initial sequence "ABC" with pointer at position 1
   - Step-by-step transformation through multiple stages
   - Final sequence is "CAB"
   - Each step shows movement of elements with arrows
   - Uses boxes to represent positions (1,2,3)

2. Example 2 shows:
   - Generalized case with sequence "1,2,...,i,i+1,...,N"
   - Pointer starts at position i
   - Final sequence is "1,2,...,N,i,...,N-1"
   - Similar box representation for positions

# Visual Patterns
1. Movement Pattern:
   - The elements after the pointer position (inclusive) undergo transformation
   - The last element of the subsequence after pointer moves to the front
   - Other elements shift right by one position
   - Elements before the pointer remain unchanged

2. Transformation Rules:
   - For sequence of length n and pointer at position p:
     * Elements [1:p-1] stay unchanged
     * Elements [p:n] are transformed by moving last element to front
     * Final sequence = original[:p-1] + [last_element] + original[p:-1]

3. Position Rules:
   - Uses 1-based indexing for pointer position
   - Valid pointer positions are between 1 and length of sequence
   - The transformation preserves the total length of the sequence

4. Cyclic Pattern:
   - The transformation involves a cyclic shift of elements after the pointer
   - Only the subsequence after (and including) the pointer position is affected
   - The shift is always by one position, with the last element moving to the front of its subsequence


# Solution
from typing import List

def solution(init_seq: List[str], ptr_pos: int) -> List[str]:
    """
    Transforms an initial sequence based on a pointer position according to specific rules.

    Args:
        init_seq: List of single characters representing the initial sequence
        ptr_pos: pointer position (1-based indexing)

    Returns:
        List of single characters representing the transformed sequence
    """
    # Handle empty sequence edge case
    if not init_seq:
        return []
    
    # Perform the "shift" operation: rotate the sequence to the right by 1
    seq_before_ptr = init_seq[:ptr_pos - 1]
    seq_after_ptr = init_seq[ptr_pos - 1:]
    seq_after_ptr_transformed = [seq_after_ptr[-1]] + seq_after_ptr[:-1]
    
    return seq_before_ptr + seq_after_ptr_transformed


# Test Script
def test():
    test_cases = [
        {
            "input": (["A", "B", "C"], 1),
            "expected": ['C', 'A', 'B']
        },
        {
            "input": (["A", "B", "C"], 2),
            "expected": ['A', 'C', 'B']
        },
        {
            "input": (["A", "B", "C"], 3),
            "expected": ['A', 'B', 'C']
        },
        {
            "input": (["A"], 1),
            "expected": ['A']
        },
        {
            "input": (["A", "B"], 1),
            "expected": ['B', 'A']
        },
        {
            "input": (["A", "B", "C", "D"], 2),
            "expected": ['A', 'D', 'B', 'C']     
        },
        {
            "input": (["1", "2", "3", "4", "5"], 4),
            "expected": ['1', '2', '3', '5', '4']
        },
        {
            "input": (["1", "2", "3", "4", "5"], 3),
            "expected": ['1', '2', '5', '3', '4']
        },
        {
            "input": (["1", "2", "3", "4", "5"], 2),
            "expected": ['1', '5', '2', '3', '4']
        },
        {
            "input": (["1", "2", "3", "4", "5"], 1),
            "expected": ['5', '1', '2', '3', '4']
        },

    ]
    
    for i, test_case in enumerate(test_cases):
        init_seq, ptr_pos = test_case["input"]
        expected_output = test_case["expected"]
        
        try:
            output = solution(init_seq, ptr_pos)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`init_seq`: {init_seq}\n"
                f"`ptr_pos`: {ptr_pos}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`init_seq`: {init_seq}\n"
                f"`ptr_pos`: {ptr_pos}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()