Given a string str, the task is to check whether the given string is linear or not. If it is linear then print “Yes” else print “No”.
Let the string be “abcdefghij”. It can be broken as:
if the character a, b, c, and are equal then the given string is linear otherwise not.
Therefore if the string is of the form “xxaxabcxabcdxabcdexab…” then it is called as the linear string.
Input: str = “aapaxyayziabcde”
All the broken string have same character as the first character.
Input: str = “bbobfycd”
Approach: To check if the given string is of the form “xxaxabcxabcdxabcdexab…” then we have to check if characters at index 0, 1, 3, 6, 10, … are equals or not.
If all the character at the above indexes are equal then the given string is Linear String otherwise it is not.
Below is the implementation of the above approach:
Time Complexity: O(log N)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Python | Check if a given string is binary string or not
- Check if a given string is a Reverse Bitonic String or not
- Check if given Binary string follows then given condition or not
- Check whether a given string is Heterogram or not
- Check given string is oddly palindrome or not
- Check if a given string is Even-Odd Palindrome or not
- Check given string is oddly palindrome or not | Set 2
- Check whether the binary equivalent of a number ends with given string or not
- Smallest string which not a subsequence of the given string
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Suffix Tree Application 4 - Build Linear Time Suffix Array
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 1
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 2
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 3
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 4
- Z algorithm (Linear time pattern searching Algorithm)
- Find number of solutions of a linear equation of n variables
- Gaussian Elimination to Solve Linear Equations
- Linear Diophantine Equations
- Solve the Linear Equation of Single Variable
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.