Your question is Rotate a String With Constraints. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Datavant processing utilities often validate equivalent identifiers and reorder event data before downstream handling. Implement a rotation check using a dedicated string-rotation helper, then implement an array item move operation.
Write these functions:
rotate_string(value, shift): return value left-rotated by shift positions. Normalize shifts larger than the string length.is_rotation(first, second): return True if second can be produced by rotating first any number of positions. This function must call rotate_string; do not solve the check with only a concatenation expression or a single inline function.move_index(values, from_index, to_index): remove the item currently at from_index and insert it at to_index in the resulting array. Return the modified array. The input array may be copied or modified in place, but the returned ordering must be correct.The required interview entry point is validate_and_move, which returns a dictionary containing the rotation result and moved array.
first and second are strings. values is a list of integers, and both indices are valid. Return {"is_rotation": bool, "array": list[int]}.
def validate_and_move(first, second, values, from_index, to_index):