LeetCode Rotate String Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

i was amazed when you added the strings and it had the required string in it as a substring!!

deepakkumar-zkhb
Автор

dude u r genius & a great teacher. made it so simple

tdsd
Автор

keep going nick!!! your explanation is awesome!

simransingh
Автор

When i heard A+A, I immediately realized and literally my whole POV of reality was questioned.

abhayzz
Автор

What a solution, brilliant trick. Thanks Nick! In my language white is ak. So we get this phrase "Rahmet Nick Ak". Rakhmet means Thanks.

ascar
Автор

Ok! So this is actually trick solution but not a general solution. First the problem has been turned into a serach problem. A substring is searched into another big string. Which in worst case may lie at the very end of the bigger string. I am not mentioning the Order of complexity here others have already done. If a much much bigger string is given say consisting of thousands or millions of characteres then this is not a right solution considering the complexity. And doubling the string would 'double' the problem.
For example, if someone is asked to 'shift' digits as characters, taken from the middle of decimal places of PI and without giving the information then? Like 2643383279 and asked to shift a number consisting of digits: 6432837239. So the given string is 2643383279 and goal is 6432837239. How many shifts will it need to reach the goal? Imagine much bigger number with many more digits (as characters). So here the problem is one of permutation. Permute the number to match a given number. How would you do it? and What will be the complexity?
Second, In Java the String class member function contains() actually searches a string with in a given string. If someone is not allowed to use this function instead asked to write the function? (like in C or in Java). So DSA is there for understanding deeply and reach an understanding to the core. There is a trick solution, a very easy one, to it.

obliquequanta
Автор

if we use Rabin-karp instead of .contains(), will it be any good in terms of time complexity?

shakib.polock
Автор

Wow, the good trick with awesome explantion! Thank you, man.

madinabonualisherova
Автор

okay how do i implement this to java, im. a new programmer and am just now starting to code for class.

rronaldo
Автор

I don't know why, but contains() is giving me error, should I use find() instead?

FANSasFRIENDS
Автор

lol😂..today my college professor asked this qn and no one can tell ..after she told this trick in c..but i need itin java ..tq nicky bro

Karthik__S_
Автор

my dumb brain couldnt figure it out and initialized a hashmap to record immediate letters only to realize testcases have duplicates

hanokreddy
Автор

Wow man !!! That's why you are best ....

crazyvaleideas