Objective In this challenge, we're going to use loops to help us do some simple math. Task Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: N x i = result . Input Format A single integer, . Constraints Output Format Print lines of output; each line (where ) contains the of in the form: N x i = result . Sample Input 2 Sample Output 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20 Explanation: Here, we just need to use for loops to achieve the result Solution : import java.io.* ; import java.math.* ; import java.security.* ; import java.text.* ; import java.util.* ; import java.util.concurrent.* ; import java.util.regex.* ; public class Solution { public static void main ( String [] args ) throws IOException { BufferedReader bufferedReader = new BufferedReader ( new InputStreamReader ( Syste
Problem Description
Rotate a given String in the specified direction by specified magnitude.After each rotation make a note of the first character of the rotated String, After all rotation are performed the accumulated first character as noted previously will form another string, say FIRSTCHARSTRING.
Check If FIRSTCHARSTRING is an Anagram of any substring of the Original string.
If yes print "YES" otherwise "NO". Input
The first line contains the original string s. The second line contains a single integer q. The ith of the next q lines contains character d[i] denoting direction and integer r[i] denoting the magnitude.
Constraints
1 <= Length of original string <= 30
1<= q <= 10
Input
carrace
3
L 2
R 2
L 3
which is not anagram of any sub string of original string "carrace".
R 2
L 3
Output:
NO
Explanation:
After applying all the rotations the FIRSTCHARSTRING string will be "rcr"which is not anagram of any sub string of original string "carrace".
Logic:
- Input the string and no.of.rotations in integer and input rotation type,position.
- Declare list for first_chars.
- Check rotation type and do rotation idx=(idx+s)%len(word) else idx=(idx-s)%len(word).
- Append the first character after every rotation.
- Check if the firstchar is a anagram of original string.
- Define function to check the count of char also.
Program:
Comments
Post a Comment