Mam.... The last condition should write out of the while loop am I right?.. Based on ur code then index may vary
@tricksforsolving28049 ай бұрын
yes ,but how its executed there ?
@shindeprem2288 ай бұрын
@@tricksforsolving2804 I also have same doubt , but I think she paused the video and then corrected it. Anyways nice explanation
@extraalt21 күн бұрын
yes or it just returns at first iteration
@nimishjaitapkar34925 ай бұрын
How is this program working with the return statement inside the while loop? 🤔
@NidhiKamble-yw2lj9 ай бұрын
Correct explanation
@tusharprajapati25743 ай бұрын
I love your approach miss!!
@Saurabh-fe2bg5 ай бұрын
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
@eshikarya4 ай бұрын
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? :)
@vageeshramesh404810 ай бұрын
Good explanation!
@sujatamahata3128 Жыл бұрын
Very nice explanation
@ramineninagajaswanth6476 Жыл бұрын
Can we do it in O(n)?
@deepakgaroda975 Жыл бұрын
Nice Explanation
@oorja1983 Жыл бұрын
Thnx.... nicely explained
@mitaalisinghal89325 ай бұрын
Nice explanation Thank You !
@TechnosageLearning5 ай бұрын
Glad it was helpful!
@start1learn-n1716 ай бұрын
Tq😊
@kadamsatyajit Жыл бұрын
good explanation
@mpbe Жыл бұрын
what about this case : ["abc","xyss","abcdefgh"] expect = "" output = "abc"
@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 Жыл бұрын
@@TechnosageLearning but the code that you taught, is not submitting successfully
@Onesided.x11 ай бұрын
@@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
@sauravclark14 күн бұрын
@@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 .
@AdarshPKumar4 ай бұрын
for test case ab , a it will go out of bound how do we solve it
@eshikarya4 ай бұрын
while(index
@saikiran-em8gw8 ай бұрын
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?
@mohittiwari69948 ай бұрын
to uspr sort v to lagyga n to fir [c, cr,crc] ho jyga
@SarthakKumar Жыл бұрын
time complexity will be nlogn because we are sorting the array right?
@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.
@DhairyaAgOfficial075 ай бұрын
Mam please start uploading videos again, your videos really helps
@inspirationalquotes5840 Жыл бұрын
substring(0, index +1) NOT substring(0, index)
@extraalt21 күн бұрын
wrong
@ec072nikitavishwakarma7 Жыл бұрын
Thankyou
@meenanandhini Жыл бұрын
mam can you explain how will you give user input using scanner class
@mohitvashisth29338 ай бұрын
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
@meenanandhini7 ай бұрын
@@mohitvashisth2933 thank you
@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 Жыл бұрын
Sure...Keep going..Let me know if you need any help
@arifmd89402 ай бұрын
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 Жыл бұрын
In the run time it is showing missing return statement
@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 Жыл бұрын
@@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 Жыл бұрын
genius
@AdarshPKumar4 ай бұрын
this will fail after the 6th test case in leetcode
@ashishnannaware73496 ай бұрын
what if array=["Thik","kuchh nhi","Thik h"] as per your code output is => Thik but output will be "" (blank)
@tanyamodi92336 ай бұрын
first sort the array, once it is sorted it will give correct output
@Aman-dh9wzАй бұрын
Bro you got ur answer.?
@Aman-dh9wzАй бұрын
@@tanyamodi9233sort karenge to 1st string me ["kuchh nhi"] and last string me [" thik hai "] .. & Then if compare so output will be " ". Na .?
@deepakmodi9275 ай бұрын
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); }
@sauravclark14 күн бұрын
@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 .
@pranavjadhav19877 күн бұрын
racecar me car suffix he prefix nahi he
@kulkarniprabhakar29011 ай бұрын
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