14721 - Gauranga Nityananda   

Description

Gaura and Nitai were fascinated by how the world shifted with each action. To make things even more interesting, they decided to swap two sections of the string, one defined by indices l1..l2 and the other by r1..r2. They could see how the world adapted, still holding its essence while changing in form. It was a true lesson in balance, showing that even in change, everything could remain connected.

 

The Mercy of Sri Gaura and Sri Nityananda, May 31, Potomac ...

 

 

TASK: 
Given a string s and two pairs of indices l1..l2 and r1..r2, swap the substrings defined by these ranges. 

If the substrings are the same, return the original string.

 

EXPLANATION: 

For sample testcase 1
Substring 1 : 
"tyana"
Substring 2 : "auran"

So by switching the indices of the 2 substrings
"G" + "auran" + "ga Ni" + "tyana" + "nda"


For sample testcase 2
Substring 1 : 
"cdefg"
Substring 2 : "fghi"

So by switching the indices of the 2 substrings
"ab" + "fghi" + "cdefg" + "jklmnop"

Input

  • The first line contains the string s (may contain spaces).

  • The second line contains four non-negative integers: l1l2r1, and r2, separated by spaces. These define the inclusive indices of the two substrings to swap (zero-indexed) 

Constraints

  • l1 <= l2 <= len(s)
  • r1 <= r2 <= len(s)

Output

  • The modified string after swapping the substrings defined by the indices l1..l2 and r1..r2. The rest of the string should remain in the same order. (with a newline)

Sample Input  Download

Sample Output  Download

Tags




Discuss