Professional Documents
Culture Documents
Problem Statement:
Consider one string as input. You have to check that given strings with single backward and forward shift
are same or not. If they are same then print 1 otherwise print 0.
Hint: -
Backward Shift: A single circular rotation of the string in which the first character becomes the last
character and all other characters are shifted one index to the left. For example, abcde becomes bcdea
after one left shift.
Forward Shift: A single circular rotation of the string in which the last character becomes the first
character and all other characters are shifted to the right. For example, abcde becomes eabcd after one
right shift
Instructions:
System doesn’t allow any kind of hard coded input value/ values.
Written program code by candidate will be verified against the inputs which are supplied from
the system.
For more clarification, please read below points carefully till the end.
Constraints:
String str should not allowed space, special character and numbers.
String str should only in English language.
Examples:
Examples -1:
Input:
sfdlmnop
Output:
Examples - 2:
Input:
mama
Output:
Explanation:
In first example, string is “sfdlmnop”.
Forward Shift:- fdlmnops
Backward Shift:- psfdlmnop
Above both strings are not equal. So output is 0.
Candidate has to write the code to accept single string value for str without any additional
message.
Output Format:
Written program code should generate output as single integer value i.e. 0 or 1 which represent
both forward and backward shift strings are equal or not.
Additional message in output will cause to failure of test cases.
CLanguage
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int len=0;
len=strlen(str);
check = false;
break;
}
}
if (check)
printf("1");
else
printf("0");
int main()
char str[100];
scanf("%s",str);
checkLeftRightString(str);
return 0;
C++Language
#include <iostream>
using namespace std;
check = false;
break;
if (check)
cout<< "1" <<endl;
else
int main()
string str;
cin>>str;
checkLeftRightString(str);
return 0;
Java
import java.util.*;
check = false;
break;
}
}
if (check)
System.out.println ("1");
else
System.out.println ("0");
checkLeftRightString(str);
Python
length = len(string)
check = True
for i in range(length):
check = False
break
if check :
print("1")
else:
print("0")
string = input()
checkLeftRightString(string)
C#
using System.IO;
using System;
class MyClass
{
public static void checkLeftRightString (String str)
{
int len = str.Length;
bool check = true;
for (int i = 0; i <len; i++)
{
if (str[i] != str[(i + 2) % len])
{
check = false;
break;
}
}
if (check)
Console.WriteLine("1");
else
Console.WriteLine("0");
}
static void Main(String[] args)
{
String str = Console.ReadLine();
checkLeftRightString(str);
}
}
Problem Statement 2:
Way of correct wrong word to correct word by removing zero or more characters.
Given strings i.e. S1 (for wrong word), S2( for correct word), find out number of was where we can
transform wrong word to correct word by removing characters from wrong word .
Example 1 :
Input :
Indiiian String S1 i.e. wrong word
Indian String S2 i.e. correct word
Output :
Example 2 :
Input :
ggoog String S1 i.e. wrong word
go String S2 i.e. correct word
Output :
Explanation: four ways will be -> "g.o..", "g..o.", “.go..” and ”.g.o.”
Input Format:
Output Format:
#include <string.h>
if (m == 0)
return 1;
int arr[m][n];
memset(arr, 0, sizeof(arr));
if (i == 0) {
if (j == 0)
arr[i][j] = arr[i][j - 1] + 1;
else
else {
if (s1[j] == s2[i])
else
}
}
int main()
int count1,count2;
char s1[100];
char s2[100];
//scanf("%s%s",&s1,&s2);
count1=strlen(s1);
count2=strlen(s2);
printf("%d",wayToChange(s1, s2,count1,count2));
return 0;
C++ Code
#include <bits/stdc++.h>
using namespace std;
int arr[m][n];
memset(arr, 0, sizeof(arr));
for (int i = 0; i < m; i++) {
for (int j = i; j < n; j++) {
if (i == 0) {
if (j == 0)
arr[i][j] = (s1[j] == s2[i]) ? 1 : 0;
else if (s1[j] == s2[i])
arr[i][j] = arr[i][j - 1] + 1;
else
arr[i][j] = arr[i][j - 1];
}
else {
if (s1[j] == s2[i])
arr[i][j] = arr[i][j - 1] + arr[i - 1][j - 1];
else
arr[i][j] = arr[i][j - 1];
}
}
}
Java Code
import java.util.Scanner;
Python Code
def wayToChange(s1, s2):
n = len(s1)
m = len(s2)
if m == 0:
return 1
if __name__ == "__main__":
string1 = input();
string2 = input();
print(wayToChange(string1, string2))
C# Code
using System.IO;
using System;
class MyClass {