# FIRSTLAST-Editorial

Author, Tester and Editorialist: Jitin

EASY

None

# PROBLEM:

You are given a string Y and you need to check whether there is a valid string X such that
we get the same string on shifting all characters in X one place left and appending the first character to as well as shifting all characters in X one place right and adding the last character at the beginning.

# EXPLANATION:

If there is a valid X then first assume Y is the string obtained by left-shifting X. Hence original string X is obtained by right shifting Y. Similarly, another original string is obtained by left-shifting Y. If both are equal then X is valid but if they are not equal, then there doesnâ€™t exist any valid X.

# SOLUTIONS:

C++ Solution
``````#include <iostream>
using namespace std;

string first_to_last(string x)
{
int n = x.length();
char first = x[0];
for (int i = 1; i < n; i++)
{
x[i - 1] = x[i];
}
x[n - 1] = first;
return x;
}

string last_to_first(string x)
{
int n = x.length();
char last = x[n - 1];
for (int i = n - 1; i > 0; i--)
{
x[i] = x[i - 1];
}
x[0] = last;
return x;
}

void solve()
{
int t;
cin >> t;
while (t--)
{
string y;
cin >> y;
// If there is a valid X then first assume Y is the left-shifted.
// Hence original string is obtained by right shifting it.
// Similarly another original string is obtained by left-shifting it
// If both are equal then X is valid.
string l = first_to_last(y);
string r = last_to_first(y);
if (l == r)
{
cout << "YES";
}
else
{
cout << "NO";
}
}
}

int main()
{
solve();
return 0;
}
``````
The text passage describes a programming problem and provides a C++ solution to determine if a valid string X can be derived from a given string Y through specific character shifts. The problem statement and solution do not contain any explicit mathematical questions or calculations.
no_question
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
# FIRSTLAST-Editorial

Author, Tester and Editorialist: Jitin

EASY

None

# PROBLEM:

You are given a string Y and you need to check whether there is a valid string X such that
we get the same string on shifting all characters in X one place left and appending the first character to as well as shifting all characters in X one place right and adding the last character at the beginning.

# EXPLANATION:

If there is a valid X then first assume Y is the string obtained by left-shifting X. Hence original string X is obtained by right shifting Y. Similarly, another original string is obtained by left-shifting Y. If both are equal then X is valid but if they are not equal, then there doesnâ€™t exist any valid X.

# SOLUTIONS:

C++ Solution
``````#include <iostream>
using namespace std;

string first_to_last(string x)
{
int n = x.length();
char first = x[0];
for (int i = 1; i < n; i++)
{
x[i - 1] = x[i];
}
x[n - 1] = first;
return x;
}

string last_to_first(string x)
{
int n = x.length();
char last = x[n - 1];
for (int i = n - 1; i > 0; i--)
{
x[i] = x[i - 1];
}
x[0] = last;
return x;
}

void solve()
{
int t;
cin >> t;
while (t--)
{
string y;
cin >> y;
// If there is a valid X then first assume Y is the left-shifted.
// Hence original string is obtained by right shifting it.
// Similarly another original string is obtained by left-shifting it
// If both are equal then X is valid.
string l = first_to_last(y);
string r = last_to_first(y);
if (l == r)
{
cout << "YES";
}
else
{
cout << "NO";
}
}
}

int main()
{
solve();
return 0;
}
``````
user
The text passage describes a programming problem and provides a C++ solution to determine if a valid string X can be derived from a given string Y through specific character shifts. The problem statement and solution do not contain any explicit mathematical questions or calculations.

TYPE: NO_QUESTION