Longest Common Prefix | LeetCode problem 14

  Рет қаралды 41,886

Technosage

Technosage

Күн бұрын

Пікірлер: 54
@srinivaschalamalasetti1877
@srinivaschalamalasetti1877 Жыл бұрын
super explanation and information also...
@memehhme
@memehhme Жыл бұрын
Mam.... The last condition should write out of the while loop am I right?.. Based on ur code then index may vary
@tricksforsolving2804
@tricksforsolving2804 9 ай бұрын
yes ,but how its executed there ?
@shindeprem228
@shindeprem228 8 ай бұрын
@@tricksforsolving2804 I also have same doubt , but I think she paused the video and then corrected it. Anyways nice explanation
@extraalt
@extraalt 21 күн бұрын
yes or it just returns at first iteration
@nimishjaitapkar3492
@nimishjaitapkar3492 5 ай бұрын
How is this program working with the return statement inside the while loop? 🤔
@NidhiKamble-yw2lj
@NidhiKamble-yw2lj 9 ай бұрын
Correct explanation
@tusharprajapati2574
@tusharprajapati2574 3 ай бұрын
I love your approach miss!!
@Saurabh-fe2bg
@Saurabh-fe2bg 5 ай бұрын
how did you enable the debuger? I am interested to know bc when you debug you get really good at coding logics and loops thoroughly
@eshikarya
@eshikarya 4 ай бұрын
You get a bug like icon in IntelliJ, that's the debugger. The first step is to apply breakpoint(s) at the line(s) of code you want to check. For example you have a loop running which prints # from 0 to n. You want to check what is going to be the print value before it's actually printed; put a breakpoint at that line and use the debugger feature step over. (There also exists step in and step out --- explore these). Right click on the code and you'll find debug option right below "run program" It took me a while to learn how to debug EFFICIENTLY, since a good debugging in my opinion is when minimum # of required debug breakpoints are put in a program. You can learn by starting to debug very simple programs (like sout("hello word"));) and then moving on to more complex programs. That's how I learned. And I agree, as a professional software engineer I can assure you a developer isn't someone who just writes and gets done with the code. Debugging will teach you more about code logics and program flows than anything else ever will. Hope this helps and answers your question? :)
@vageeshramesh4048
@vageeshramesh4048 10 ай бұрын
Good explanation!
@sujatamahata3128
@sujatamahata3128 Жыл бұрын
Very nice explanation
@ramineninagajaswanth6476
@ramineninagajaswanth6476 Жыл бұрын
Can we do it in O(n)?
@deepakgaroda975
@deepakgaroda975 Жыл бұрын
Nice Explanation
@oorja1983
@oorja1983 Жыл бұрын
Thnx.... nicely explained
@mitaalisinghal8932
@mitaalisinghal8932 5 ай бұрын
Nice explanation Thank You !
@TechnosageLearning
@TechnosageLearning 5 ай бұрын
Glad it was helpful!
@start1learn-n171
@start1learn-n171 6 ай бұрын
Tq😊
@kadamsatyajit
@kadamsatyajit Жыл бұрын
good explanation
@mpbe
@mpbe Жыл бұрын
what about this case : ["abc","xyss","abcdefgh"] expect = "" output = "abc"
@TechnosageLearning
@TechnosageLearning Жыл бұрын
Output would be an empty string in this case...because abc is not common prefix in all three strings..It should be there in all strings then only it would be considered as common prefix..
@mpbe
@mpbe Жыл бұрын
@@TechnosageLearning but the code that you taught, is not submitting successfully
@Onesided.x
@Onesided.x 11 ай бұрын
​@@mpbebro array ko sort karenge toh ab ab se start hone wali string pehle aa jayegi or xy se start hone wali string last me aa jayegi toh comparison first string or last string ka hoga toh koi character match nhi hoga toh output empty string hi aayega na
@sauravclark
@sauravclark 14 күн бұрын
@@Onesided.x isko check karo then, is it working? Leet code accept nahi kar raha , q ki is logic se dekhe to original array = ["dog","racecar","car"] sorting ke baad = [car, dog, racecar], to comparison first string aur last string main hua to answer car aayega as common prefix , but car dog main to nahi hai , fir? isliye leetcode main submit nahi ho raha .
@AdarshPKumar
@AdarshPKumar 4 ай бұрын
for test case ab , a it will go out of bound how do we solve it
@eshikarya
@eshikarya 4 ай бұрын
while(index
@saikiran-em8gw
@saikiran-em8gw 8 ай бұрын
What if [ cr, c , crc]....in this case,after checking 1st and last string common letters will be cr,but middle string contains only c...how its works with ur logic?
@mohittiwari6994
@mohittiwari6994 8 ай бұрын
to uspr sort v to lagyga n to fir [c, cr,crc] ho jyga
@SarthakKumar
@SarthakKumar Жыл бұрын
time complexity will be nlogn because we are sorting the array right?
@TechnosageLearning
@TechnosageLearning Жыл бұрын
Yes it would be logarithmic time Complexity..By mistake, I have mentioned as O(n)....I will correct it. Thanks for pointing it out.
@DhairyaAgOfficial07
@DhairyaAgOfficial07 5 ай бұрын
Mam please start uploading videos again, your videos really helps
@inspirationalquotes5840
@inspirationalquotes5840 Жыл бұрын
substring(0, index +1) NOT substring(0, index)
@extraalt
@extraalt 21 күн бұрын
wrong
@ec072nikitavishwakarma7
@ec072nikitavishwakarma7 Жыл бұрын
Thankyou
@meenanandhini
@meenanandhini Жыл бұрын
mam can you explain how will you give user input using scanner class
@mohitvashisth2933
@mohitvashisth2933 8 ай бұрын
import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner input = new Scanner(System.in); int n = input.nextInt(); String words[] = new int[n]; for(int i=0; i
@meenanandhini
@meenanandhini 7 ай бұрын
@@mohitvashisth2933 thank you
@karanjitrandhawa1515
@karanjitrandhawa1515 Жыл бұрын
Understood Maam, Maam can you please guide me. I am ready to do hard work and doing also one thing i need the most is the guidance please
@TechnosageLearning
@TechnosageLearning Жыл бұрын
Sure...Keep going..Let me know if you need any help
@arifmd8940
@arifmd8940 2 ай бұрын
Wrong code, it will only work for the first two strings in that array. Its going to ignore the rest of the strings in that array
@ayanchakraborty3067
@ayanchakraborty3067 Жыл бұрын
In the run time it is showing missing return statement
@TechnosageLearning
@TechnosageLearning Жыл бұрын
class Solution { public String longestCommonPrefix(String[] strs) { Arrays.sort(strs); String str1 = strs[0]; String str2 = strs[strs.length-1]; int index =0; while(index
@Yogesh-ei1lg
@Yogesh-ei1lg Жыл бұрын
@@TechnosageLearning Yeah, that's perfectly fine. In the video, you are also using main function that is why the return statement needs to change its position according toh the situation.
@abhinavpatil2114
@abhinavpatil2114 Жыл бұрын
genius
@AdarshPKumar
@AdarshPKumar 4 ай бұрын
this will fail after the 6th test case in leetcode
@ashishnannaware7349
@ashishnannaware7349 6 ай бұрын
what if array=["Thik","kuchh nhi","Thik h"] as per your code output is => Thik but output will be "" (blank)
@tanyamodi9233
@tanyamodi9233 6 ай бұрын
first sort the array, once it is sorted it will give correct output
@Aman-dh9wz
@Aman-dh9wz Ай бұрын
Bro you got ur answer.?
@Aman-dh9wz
@Aman-dh9wz Ай бұрын
​@@tanyamodi9233sort karenge to 1st string me ["kuchh nhi"] and last string me [" thik hai "] .. & Then if compare so output will be " ". Na .?
@deepakmodi927
@deepakmodi927 5 ай бұрын
public String longestCommonPrefix(String[] strs) { Arrays.sort(strs); // sort the array of strings String first = strs[0]; String last = strs[strs.length - 1]; int i = 0; // find the common prefix between the first and last string while (i < first.length() && i < last.length()) { if (first.charAt(i) == last.charAt(i)) { i++; } else { break; } } return i == 0 ? "" : first.substring(0, i); }
@sauravclark
@sauravclark 14 күн бұрын
​ @Onesided.x isko check karo then, is it working? Leet code accept nahi kar raha , q ki is logic se dekhe to original array = ["dog","racecar","car"] sorting ke baad = [car, dog, racecar], to comparison first string aur last string main hua to answer car aayega as common prefix , but car dog main to nahi hai , fir? isliye leetcode main submit nahi ho raha .
@pranavjadhav1987
@pranavjadhav1987 7 күн бұрын
racecar me car suffix he prefix nahi he
@kulkarniprabhakar290
@kulkarniprabhakar290 11 ай бұрын
Just a little improvement: while(i < str1.length() && str1.charAt(i) == str2.charAt(i)) { i++; } return i == 0 ? "" : str1.substring(0,i); make it more simple like this
@shruuuuuuu21
@shruuuuuuu21 5 ай бұрын
Nice bro good logic
Reverse words in a string | Leetcode problem 151
6:08
Technosage
Рет қаралды 48 М.
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН
LeetCode 14. Longest Common Prefix Solution Explained - Java
6:33
Lecture 80: Longest Common Prefix Problem || Tries || C++ Placement Series
20:17
Longest Common Prefix - Leetcode 14 - Python
6:31
NeetCode
Рет қаралды 196 М.
Longest Common Prefix | LeetCode problem 14 | Tamil Explanation
8:02
Karthi Stucks At Code
Рет қаралды 326
How I learned to code in 3 months (and got several offers)
12:54
Coding Jesus
Рет қаралды 213 М.
Longest common prefix
14:24
Techdose
Рет қаралды 80 М.