Most Common Core Java String Coding Interview Question | Leetcode| String Rotation |Code Decode

preview_player
Показать описание
In this video of code decode we have explained find if one string is a rotation of another i.e. string rotation problem. It is the most commonly asked core java string interview question and answer

Udemy Course of Code Decode on Microservice k8s AWS CICD link:

Course Description Video :

Appraisals are not always about salary hikes. After working hard for a whole year, we want greater responsibilities, promotions, work life balance, and so much more!
If your current job can't give this to you, just hop on to Hirect.
On Hirect you can search for the job you want and chat directly with startup founders and CEOs to get hired quickly.
Also, no consultants are involved here.
So, what are you waiting for?

and #CareerHikeKarkeTohDekho

given a string = "decode"
left rotation of string with 2 characters is = "codede"
right rotation of string with 2 characters is "dedeco"

To find if one string is rotation of another String by using a solution- is to concatenate s1 with itself. s2 is a rotation of s1 if and only if it is a substring of the rotated string. In java we can either use string contains or indexOf to check for substring.

Subscriber and Follow Code Decode

#codedecode #Stringrotation#stringinterviewquestion
Рекомендации по теме
Комментарии
Автор

Very clear and easy explanation, Thank you so much

refreshjavabysaikaruturi
Автор

private static void leftShift(String str, int r) {

String outputString = str.substring(r) + str.substring(0, r);


}

private static void rightShift(String str, int r) {
int partition = str.length() - r;
leftShift(str, partition);

}

qaimmahdi
Автор

Thank you very much maam. Looking forward for some hard ds, algo questions from codeforge or leetcode for our interview.

akashsaha
Автор

Just an additional comment..
We should also add length check that both strings are of same length to handle false positive for smaller string

littlegenius
Автор

public void rotate(String str, int n, boolean left){
If(left==true){
System.out.println(str.subString(n)+str.subString(0, n));}
else System.out.println(str.subString(str.length()-1-n, str.length()-1) + str.subString(0, str.length()-1-n);
}

ig_haxie
Автор

Can you please create a detailed video on java concurrent package. Now a days most of the interviewers are asking questions from this topic.

ruchigupta
Автор

Thank you so much for your great work.!! All videos are simple and in detail...
Could you please make a video to find maximum sum from an array/arraylist which contains +ve and -ve values.

suparnasuresh
Автор

You should the length of the "rotated" word and also check is not the same word. As it is decode will also return true as if it was a rotated word from decode which is not. Also de should return true and it is not a rotation of the word.

andresfelipecardonagutierr
Автор

Thank you so much mam. Your explanation is very clearly.

karnataka
Автор

Excellent explanation. Thanks for sharing.

vengateshm
Автор

public class RotateLeftAndRight {
public static void main(String[] args) {

// Rotate by left
System.out.println(leftRotate("Hello", 2));

// Rotate by right
System.out.println(rightRotate("Hello", 2));

// Using left rotation to get the right rotation
// Left rotation - 2
// Right rotation - 2 ~ Left Rotation (total length - 2)
System.out.println(rightRotateUsingLeftRotation("Hello", 2));
}

private static String word, int r) {
System.out.print("Right roation using ");
return leftRotate(word, word.length() - r);
}

public static String leftRotate(String word, int r) {
System.out.println("Left Rotation by " + r);
return word.substring(r) + word.substring(0, r);
}

public static String rightRotate(String word, int r) {
System.out.println("Right Rotation by " + r);
int index = word.length() - r;
return word.substring(index) + word.substring(0, index);
}
}

thulasiraman
Автор

Thank you, please also make some tutorials in solving the leetcode questions

sreedattakandinalli
Автор

Please make one video on How to call stored procedure in spring boot

akshaykohale
Автор

Can you please make a vedio on object lock and class level lock

ashwinis.
Автор

Dear mam please restart aws series ASAP.

trendinggadgets
welcome to shbcf.ru