The idea is simple. We will use binary search to find the square root of the number. If the given number is not a perfect square then we will simply take the floor value of the root of the number.
We will discuss an easy approach to generate all the rotations of a string. Approach is simple we will concatenate the given string with itself and then we will be able to generate all the rotations. C++ Program to generate all the rotations of a given string is given below along with its algorithm.
In this program an array is given to you and you have to find the peak elements in the array.. A peak element in the array is the element which is greater than its left and right elements. Therefore, There can be multiple peak elements in the array.
C++ Program to reverse the vowels of a string is given below. Approach is simple, we will use two pointer approach. First we will initialize a counter at the start of the string and the other one is at the end of the string. Time complexity of the program given below is O(n) and space complexity is O(1).