Cha Cha Slide C++
Suppose we have two strings s and t. we have to check whether s is rotation of t or not, in other words, can we get t after rotating s?
So, if the input is like s = "helloworld" and t = "worldhello", then the output will be True.
To solve this, we will follow these steps −
if size of s0 is not equal to size of s1, then −
s := s0 concatenate s0
return true when s1 is in s, otherwise 0
Let us see the following implementation to get better understanding −
Example
Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool solve(string s0, string s1) {
if(s0.size() != s1.size())
return false;
string s = s0 + s0;
return s.find(s1) != string::npos;
}
};
int main(){
Solution ob;
cout << (ob.solve("helloworld", "worldhello"));
}
Input
"helloworld", "worldhello"
Output
1
Related Articles
- Slide Puzzle Using Python PyGame
- Study Pollen Germination on a Slide
- Create Left to Right slide animation in Android?
- How to show Slide down to textview in android
- Create Left to Right slide animation in Android using Kotlin.
- How to create image overlay hover slide effects with CSS?
- How to make an Android SlidingDrawer slide out from the left?
- Slide up and down of a div animates its content - jQuery?
- How to design a video slide animation effect using HTML CSS JavaScript?
- Why is the surface of a slide polished to make it smooth?
- How to make an Android SlidingDrawer slide out from the left in Kotlin?
- A student has to observe a permanent slide of binary fission in Amoeba. Find the correct sequence of steps given below for focusing the object under a microscope.a. Place the slide on the stage, look through the eye-piece and adjust the mirror to get proper illumination.b. Focus the slide sharp using fine adjustment screw.c. Look through the eye-piece and raise the objective lens using coarse adjustment screw till the object is focused.d. Look through the eye-piece and move the slide till the object is visible.(a) a, c, d, b (b) d, c, b, a(c) a, b, d, c (d) a, d, c, b
- A lens of focal length 20 cm is used to produce a ten times magnified image of a film slide on a screen. How far must the slide be placed from the lens?
- How to Show and hide a View with a slide up/down animation in android?
- After Examining a Prepared Slide Under the High Power of a Compound Microscope, A Student Concludes That the Given Slide Shows the Various Stages of Binary Fission in A Unicellular Organism. Write Two Observations On the Basis of Which Such a Conclusion May Be Drawn
Kickstart Your Career
Get certified by completing the course
Get Started