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
Click here to get All Company Coding + Interview Questions and Programs
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.
1 Comments
Harrah's Lake Tahoe, Stateline - Mapyro
ReplyDeleteThe Harrah's Lake Tahoe is an iconic hotel 파주 출장안마 and casino situated in Stateline, Nevada, just north of Stateline. The hotel features a 충주 출장안마 casino, 광명 출장마사지 spa, and a Address: 1375 Stateline 충주 출장안마 Blvd S, Stateline, NV 89109Phone: +1 702 770 부천 출장안마 7000