pyassistant

Rotate Each Word Right by k

Given a string s containing words separated by spaces and a non-negative integer k, rotate each word to the right by k positions (cyclically). Return the transformed string. A rotation by k means moving the last k characters of the word to its front. If k is larger than the word length, use k modulo word length. Preserve the original spacing between words (i.e., treat consecutive spaces as separators and keep empty segments).

Example:

Input:
("hello world", 2)
Output:
"lohel ldwor"

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.