# Amdocs Coding Question | Rotated String

Hello friends, I hope you all are doing great. In this post today we will learn to solve the  coding questions which is being asked by the Amdocs company recently. If you are preparing for selection in any company then this post will help you definitely.

Lets Start

Rotated String

Given a string a , and flag (-m or m) , you are required to write a function that does the following: if flag=m : rotate the elements of the string a,m elements right. if flag=-m: rotate the elements of the string a,m elements left.

The function prototype is :

rotateString(String a, int flag):

a-the string to be rotated

flag- if flag=m : rotate the elements of the string a,m elements right otherwise left.

The function should return rotated string.

Example :-

• Input:
• Easy
• -1
• Output:
• asyE

Explanation:-

Since the flag is negative so it will rotate left.

Code in Python

```#Code in Python
class TestImpl:
def rotateString(self,a,flag):
if flag>0:
return a[len(a)-flag]+a[0:len(a)-flag]
else:
return a[abs(flag):] + a[0:abs(flag)]

#Drive code
obj=TestImpl()
print(obj.rotateString("Easy",-1))

"""
OUTPUT
asyE
"""
```

Code in Java
```import java.util.Scanner;

class RotateString {

static String rotateString(String a, int flag) {
if (flag > 0) {
return a.substring(a.length() - flag) + a.substring(0, a.length() - flag);
} else {
return a.substring(Math.abs(flag)) + a.substring(0, Math.abs(flag));
}
}

public static void main(String[] args) {
System.out.println( rotateString("Easy", -1));
}
}
/*
OUTPUT
asyE
*/
```

Request:-If you found this post helpful then let me know by your comment and share it with your friend.

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other.

Thanks