Rotation Check

Rotation Check

Medium PHP PHP Strings 38 views
Explanation Complexity

Problem Statement

Check if b is a rotation of a (case-sensitive). Print YES or NO.

Input Format

Two lines a and b.

Output Format

YES or NO.

Example

abcd
cdab
YES

Constraints

|a|,|b|

Input / Output Format

Input Format
Two lines a and b.
Output Format
YES or NO.
Constraints
|a|,|b|

Examples

Input:
abcd cdab
Output:
YES

Example Solution (Public)

PHP
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputLines=preg_split('/\\R/', $inputText);
$a=$inputLines[0] ?? '';
$b=$inputLines[1] ?? '';
if(strlen($a)!==strlen($b)){ echo 'NO'; exit; }
$twice=$a.$a;
echo (strpos($twice,$b)!==false) ? 'YES' : 'NO';
?>

Official Solution Code

<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputLines=preg_split('/\\R/', $inputText);
$a=$inputLines[0] ?? '';
$b=$inputLines[1] ?? '';
if(strlen($a)!==strlen($b)){ echo 'NO'; exit; }
$twice=$a.$a;
echo (strpos($twice,$b)!==false) ? 'YES' : 'NO';
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.