Interview Question: Print 1 to 100 Without Using for/while/do-while Loop in Code || Using Recursive

  Рет қаралды 292,576

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 284
@prasannaprasy950
@prasannaprasy950 3 жыл бұрын
Hi Naveen i am holding three best product based company offer only because of you!! i am claering all the interviews which are coming on my way no matter whther it is manual, automation, api, selenium, bdd, microservice, everything i am clearing in single shot...seriouly i dont have words to praise you..Thanks a lotttttt for evrything❤️❤️....Stay blessed forever!!!! If possible i definately need to meet and take blessings of you!!
@GreatStoriesTakeTime
@GreatStoriesTakeTime 3 жыл бұрын
Cab you share me the API interview questions or from which site you prepared ??
@hemakeerthi5709
@hemakeerthi5709 3 жыл бұрын
Can you guide us??? From where you have prepared and what to prepare?
@mahatheedandibhotla
@mahatheedandibhotla 3 жыл бұрын
@@GreatStoriesTakeTime Dont prepare for interview learn the subject as a whole if u learn it you dont need interview questions at all
@prasannaprasy950
@prasannaprasy950 3 жыл бұрын
Hi all i consantly followed naveen automation labs from past one year and consumed how much ever knowledge i could, that is the reason i am able to clear all the interviews now..if u r strong in subject u can answer any question coming at you!! All the best everyone!!👍
@yuvasrivanth
@yuvasrivanth 3 жыл бұрын
@@prasannaprasy950 great both of you
@souvikchatterjee7400
@souvikchatterjee7400 3 жыл бұрын
Streams concept did not come to my mind. I solved this using recursion in one of my interviews. Thanks for sharing Naveen
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
All the best
@somnathsahoo5547
@somnathsahoo5547 3 жыл бұрын
Do u get asked ?or run
@buttofthejoke
@buttofthejoke 3 жыл бұрын
forEach is literally a loop. And recursion is an obvious alternative to looping.
@ozrenbalic6051
@ozrenbalic6051 3 жыл бұрын
@@buttofthejoke it isn't a loop, it is a higher order method. How it is implemented is irrelevant from the caller's point of view.
@buttofthejoke
@buttofthejoke 3 жыл бұрын
@@ozrenbalic6051 What? You mean forEach does not loop over each item? You can implement a forEach where it doesn't loop? can you give a quick sample? I need to know if my life was a lie. (or yours is)
@suman-majhi
@suman-majhi 3 жыл бұрын
Underrated channel.... People love masala content, not quality content. Subscribed after watching such a quality content😊😊
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thank you so much 😀
@MerryEveryday
@MerryEveryday 3 жыл бұрын
I was about to sleep but the caption bugged me and I couldnt help myseld but watch this video. Thanks! Such simple tricks but we just need to remember it on time
@BhavyaTyagi16
@BhavyaTyagi16 3 жыл бұрын
That's what happened with me right now. 3:07 am. 😂
@mohammedayesh1378
@mohammedayesh1378 3 жыл бұрын
same at 6:23am
@meyashtiwari
@meyashtiwari 3 жыл бұрын
ForEach is also a loop, using it kinda defeats the purpose of the question, right?
@AmitKumar-si3yd
@AmitKumar-si3yd 3 жыл бұрын
I agree, I don't think ForEach is a good solution if we can't use loop.
@user-id2nj2co1q
@user-id2nj2co1q 3 жыл бұрын
Yeah, exactly what I was thinking. Then the loop just gets executed in some library code
@roopakbedekar3281
@roopakbedekar3281 3 жыл бұрын
That is exactly what i thought when he wrote it. forEach also iterates for all the items in the list/array so its one or the same as a loop
@vrtex17
@vrtex17 3 жыл бұрын
Not really, it's just a method that happens to have "loop" in it's name.
@simonmultiverse6349
@simonmultiverse6349 3 жыл бұрын
@@vrtex17 ...and also happens to behave like a loop.
@k-ai-ros
@k-ai-ros 3 жыл бұрын
No loops, not recursion loop also... void printNumbersWithoutLoop() { BitSet bitSet = new BitSet(); bitSet.set(0, 101); String substring = bitSet.toString() .replaceAll("\\{|, |}", " "); System.out.println(substring); }
@aleksanderf4672
@aleksanderf4672 3 жыл бұрын
You speak the language of Gods.
@buthow900
@buthow900 3 жыл бұрын
Replace all uses loops inside xD
@sunny-mx9ff
@sunny-mx9ff 3 жыл бұрын
how can we do this in C++?? like is there any way we can achieve the same task(printing 1-100) with same constraints(no loops or recursion) in C++???
@hezekiahbranch5461
@hezekiahbranch5461 3 жыл бұрын
Thought I'd share the recursive Python version if anyone was interested: def print_100(num): if num > 100: return else: print(num) return print_100(num + 1) print_100(1)
@atrumluminarium
@atrumluminarium 3 жыл бұрын
There's a one-liner way to do it in python using lambdas and conditional assignments if you exploit the fact that the arguments for the "or" keyword are executed in chronological order: print100 = lambda num: print(num) or print100(num+1) if num
@DJ-rf8kz
@DJ-rf8kz 3 жыл бұрын
@@atrumluminarium why does it check both conditions? i thought ‘or’ only chooses 1?
@atrumluminarium
@atrumluminarium 3 жыл бұрын
@@DJ-rf8kz it chooses only one if the first argument is "True" (I believe the technical term for this is short circuiting). However "print()" returns "None" which python interprets as "False" so it checks the second argument as well which in this case is the recursion
@calebfuller4713
@calebfuller4713 3 жыл бұрын
def print_to_100(n): print(n) if n
@calebfuller4713
@calebfuller4713 3 жыл бұрын
@@atrumluminarium print(*set(range(1,101)),sep=" ")
@OmkarBawkar
@OmkarBawkar Жыл бұрын
I was asked this question in Paytm first round....Thanks to you I write the code successfully and execute it by using a Recursive function.
@petribalanceisnice
@petribalanceisnice 3 жыл бұрын
For real though, how is that without any loop? Recursive function feels like the definition of loop Edit: I mean "if" in this case just becomes another "while"
@kazedcat
@kazedcat 3 жыл бұрын
It acts like a loop but it is not a loop. At machine level recursive function manipulates the stack but a loop is just a simple branch instruction.
@angeldude101
@angeldude101 3 жыл бұрын
@@kazedcat Except many compilers are smarter than that and, if the recursion is written properly, will transform it into a loop that reuses its stack space.
@randomactsofgaming845
@randomactsofgaming845 3 жыл бұрын
The real question for me is why would you not just use a loop? I mean yea it’s an interesting challenge I guess, but we have developed loops specifically for these kinds of reasons. This is the equivalent of telling someone to try mowing their grass without using their lawnmower. If you’re going to teach someone somethings about programming teach them to use the tools available to them not to ignore those tools.
@kazedcat
@kazedcat 3 жыл бұрын
RandomActs OfGaming Part of programming is problem solving. This is just a toy problem to let people use the tools instead of just memorizing them. The value of this problem is it allow you to spot people who did not really understand programming.
@randomactsofgaming845
@randomactsofgaming845 3 жыл бұрын
@@kazedcat Part of programming is indeed problem solving. Also part of programming is using the right tools in the right situations. So many people think oh you have to be fancy can you do this without using the if statement? can you do that without using loops? That's not problem solving at all, there's never going to be a scenario where you are going to print out 1 to 100 in a console that a loop isn't going to be your best option. Those are just games and they have no real world application. What I want to know is can you use an if statement correctly, do you know when it's appropriate to use a loop and when it's not? And most importantly can you write software that works? Programming is greatly affected by opinion and you are entitled to your own but having been the lead developer on multiple projects I can tell you right now I would much rather have a developer who knew when to use a loop statement to get the job done than one who wasted my time trying to figure out a way not to use the tools supplied to them by the language.
@tushar1038
@tushar1038 3 жыл бұрын
Explanation is straight forward and clear👍👍
@badlydrawnjolteon646
@badlydrawnjolteon646 3 жыл бұрын
in python: print(*list(range(100)), sep=' ')
@DJ-rf8kz
@DJ-rf8kz 3 жыл бұрын
nice solution, range should be 101 though. 👍🏽
@badlydrawnjolteon646
@badlydrawnjolteon646 3 жыл бұрын
Darian Jennings shit your right, actually it should be range(1, 101)
@DJ-rf8kz
@DJ-rf8kz 3 жыл бұрын
@@badlydrawnjolteon646 yea true to get rid of the zero too. 👌🏽
@skeppy8925
@skeppy8925 3 жыл бұрын
@@badlydrawnjolteon646 wouldn’t it be (1,101,1)? Last interger means it would go by increments of 1? Or is that for another function?
@badlydrawnjolteon646
@badlydrawnjolteon646 3 жыл бұрын
@@skeppy8925 you dont need to specify 1. range(100) = 0, 99 range(1, 100) = 1, 99 range(1, 100, 1) = 1, 99 step defaults to 1 start defaults to 0 range(start, stop, step) are the parameters
@matthiasendler7268
@matthiasendler7268 3 жыл бұрын
The IntStream also has a static rangeClosed method, where the start and the end are inclusive: IntStream.rangeClosed(1, 100).forEach(System.out::println);
@thekwoka4707
@thekwoka4707 3 жыл бұрын
forEach() is a for loop.
@matthiasendler7268
@matthiasendler7268 3 жыл бұрын
@@thekwoka4707 well, it does not matter, because it could be well be recursion, but it is not. It's just an implementation detail of the forEach method of streams. You could use a map method, but it will always have some kind of loop construct under its belt in Java, because recursion will grow the stack as there is no tail call optimization in java... In Erlang, you would not grow the stack, as there is tail call optimization included and you have to use recursion, because there are no loop constructs available.
@dasten123
@dasten123 3 жыл бұрын
// Without loops and without recursion: import java.util.*; public class HelloWorld { static int n = 0; public static void main(String[] args) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (n++ >= 100) timer.cancel(); else System.out.println(n); } }, 0, 1); // runs task every 1 ms } }
@miningape
@miningape 3 жыл бұрын
Technically Timer uses a loop so all you've really done is hidden the implementation
@simonmultiverse6349
@simonmultiverse6349 3 жыл бұрын
I prefer to split the task to minimise stack usage. I use divide and conquer. define print(lo,hi) and make sure that they are integers. there are 3 cases: Case 1: if lo>hi, do nothing and return Case 2: if lo=hi, print lo and return Case 3: (now we know that lo
@PandorasFolly
@PandorasFolly 3 жыл бұрын
System.out.println("1 to 100 without using any loop") They never said print in an increasing fashion every number between and including 1 to 100. Also solid video my man. Good job.
@calebkirschbaum8158
@calebkirschbaum8158 3 жыл бұрын
The 2 ways that came to my mind was 1st, recursive as you did. But an even faster way is possible, that is only one line long. print(1 2 3 4 5 6...99 100)
@k.ravichandra1049
@k.ravichandra1049 2 жыл бұрын
Thanks a Ton NAVEEN for covering this Tricky Interview Question. Great Keep up the Good work.
@rajatgarg582
@rajatgarg582 3 жыл бұрын
hi naveen you are doing great job by creating these kind of video... these are really helpful. thanks buddy. Really appreciate your efforts.
@Ferdam
@Ferdam 3 жыл бұрын
if forloop method isn't a loop then I could as well just write a class that does loops and call it. Recursion should be the only one accepted hehe
@yunpengling1488
@yunpengling1488 3 жыл бұрын
Thank you very much for this video, Sir, I have a good time while learning with you. Cheers
@calebfuller4713
@calebfuller4713 3 жыл бұрын
You can do it in one line with Julia: print(join(1:100," ")) This is probably the best way. If you want a recursive function though, the Julia version is: printrange(s,n) = begin println(s) if s
@sanketbari2826
@sanketbari2826 3 жыл бұрын
Spilt(",") Strip()
@calebfuller4713
@calebfuller4713 3 жыл бұрын
@@sanketbari2826 Thanks. Join() was the function I needed. Check my edited post with the new one-liner.
@sachinj7899
@sachinj7899 3 жыл бұрын
Thanks naveen sir. Start loving programming because of you...Keep inspiring .
@Arnankhan
@Arnankhan 3 жыл бұрын
/* I have another idea. You can use an if statement and go-to statement to emulate a loop. */ #include using namespace std; int main (){ int n = 1 top: cout
@nirmanmalaviya9134
@nirmanmalaviya9134 3 жыл бұрын
This will go into a infinite loop. You never incremented n.
@Arnankhan
@Arnankhan 3 жыл бұрын
@@nirmanmalaviya9134 Updated it.
@sanketbari2826
@sanketbari2826 3 жыл бұрын
Nice idea....But goto is deprecated
@ozrenbalic6051
@ozrenbalic6051 3 жыл бұрын
I think that "printNum(num+1)" is cleaner (and more concise) than "num++; printNum(num)". Mutating num is unnecessary, we are not using new value of num after the recursive call.
@swarnasharma3836
@swarnasharma3836 3 жыл бұрын
public class PrintHundredWithoutLoop { public static void main(String[] args) { int i = 1; printNumber(i); } public static void printNumber(int n) { if(n
@shantomanob5964
@shantomanob5964 3 жыл бұрын
Else block redundant
@joelmason6818
@joelmason6818 3 жыл бұрын
Do realize that this has limits. If you stack these functions to far, you'll get a stack overflow error. Here's a challenge for you. Research knights tour. Create a recursive function for path finding. You'll find this to be an extremely awesome mental exercise! 😁
@shilpabhuti1659
@shilpabhuti1659 3 жыл бұрын
Hi Naveen, Thanks for the amazing content you are providing. Requesting you to make a playlist on puzzle programs. Awaiting your response.😀 Thank you ☺️
@fyzxnerd
@fyzxnerd 3 жыл бұрын
I've always thought of recursion as a loop. Definitely see some drawbacks though if you're not printing numbers but instead apply this as a clock. The stream/lambda function though makes sense to me.
@NomoregoodnamesD8
@NomoregoodnamesD8 3 жыл бұрын
this function is tail-recursive which means that it doesn't do any additional work after recursing. In practice, tail-recursive functions and forloops execute at about the same speed because the function stack of a tail-recursive function can be reused.
@TheRealFigLizard
@TheRealFigLizard 3 жыл бұрын
In Python you can use map() which functions similarly to the Stream method. Something like list(map(print,list(range(1,101))))[1] should work in Python 3 if you can excuse all of the parens.
@adityaraut9364
@adityaraut9364 3 жыл бұрын
After watching your videos, I always think why this didn't came to my mind?!?!
@samphire
@samphire 3 жыл бұрын
Why does everyone try to be smart and forget the simple way, cut and paste with an increment operator, the question didn't ask for reusable/alterable/compact code ;)
@ljose007
@ljose007 3 жыл бұрын
Thanks, this was very helpful to me using C#. I used the same code with the exception of sout. I used writeline() instead. using System; using static System.Console; //using a recursive function namespace PrintNumberNoLoop { class Program { static void Main(string[] args) { PrintNumber(0,10,2);// Prints 0, 2,4,6,8 ,10 } public static void PrintNumber(int begin, int end, int increment) { if(begin
@jimmorrison2657
@jimmorrison2657 3 жыл бұрын
I don't like these sorts of questions. I think this question is just a parlor trick. To me, it doesn't really test to see if the person is a good programmer. They should be testing for cleanness and clarity of code, SOLID knowledge etc. But anyway, sometimes they do ask questions like this, so good video!
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Ya Jim, just a quick Interview question. Someone asked this so thought of creating this video.
@adjmonkey
@adjmonkey 3 жыл бұрын
Tbf, this type of quick thinking is definitely needed to be a good programmer. If all you can do is use a framework and cry when something doesn’t work, you’re replaceable
@jimmorrison2657
@jimmorrison2657 3 жыл бұрын
@@adjmonkey If someone can only use a framework and cries when it doesn't work, they wouldn't be a very good employee. That's true, but that wasn't in question. What I meant was that I have seen programmers who know lots of cute little tricks like this, but can't write readable, well-structured code. Personally, I would prefer the programmer who can write good code, but who doesn't know any these tricks. If they know both things, even better.
@saiadityapotham3593
@saiadityapotham3593 3 жыл бұрын
Thanks bro 2nd method was new to me Java streams🙏
@anmolmalhi5670
@anmolmalhi5670 3 жыл бұрын
Hello Naveen, Thanks to your wonderful videos , i got my new job in the market. what you prefer me to learn for mobile browser testing and debugging. I already worked with selenium to use mobile emulator and sauce labs and browser stack. I am not sure about the UI testing for mobile browser testing, do you have any specific video for mobile browser testing?
@CallumPooleProgrammer
@CallumPooleProgrammer 3 жыл бұрын
Gotta be careful of stack overflow if the range passed into the printNumber is too large
@s12312321312
@s12312321312 3 жыл бұрын
U deserve a subscribe sir! Thank you so much.
@chetankat007
@chetankat007 3 жыл бұрын
Remember use recursion only when there are no IO intensive operations involved..or the system will stop responding..
@suganthiezhilmani3729
@suganthiezhilmani3729 3 жыл бұрын
I guess we can use stream iterate method to generate values and collect them in a list to avoid using forEach method. List num = Stream.iterate(1,n-> n+1).limit(100).collect(Collectors.toList()); System.out.println(num);
@nvmcomrade
@nvmcomrade 3 жыл бұрын
Another way is to receive a string containing all the numbers into the main args and print it, then have a script running the program with the correct input. Also in C/C++ you can use macros and unroll a 100 statements quickly #include #define call_5(x) x; x; x; x; x; #define call_10(x) call_5(x) call_5(x) #define call_100(x) call_10( call_10(x) ) int main() { int i = 1; call_100( printf( "%d ", i ); i++; ); return 0; } In C++17 you can do this: #include template void printN_impl( std::index_sequence ) { ((std::cout
@atrumluminarium
@atrumluminarium 3 жыл бұрын
There's a one-liner way to do it in python using lambdas and conditional assignments if you exploit the fact that the arguments for the "or" keyword are executed in chronological order: print100 = lambda num: print(num) or print100(num+1) if num
@luketurner314
@luketurner314 3 жыл бұрын
I'll do you one better: print(*list(range(1,101)),sep=' ') unless range uses loops internally
@atrumluminarium
@atrumluminarium 3 жыл бұрын
@@luketurner314 I saw this variation already in another comment thread on this video it's really neat. Also you do not need the cast to list because range returns a generator and *args can unwrap generators too (which is where the loop happens under the hood but all function arguments parse using a loop so it can't really be avoided I think) So you end up with print(*range(1,101), sep=' ')
@sanketbari2826
@sanketbari2826 3 жыл бұрын
Please make videos on dynamic programming .... tough questions....We know recursion but when it comes to dynamic programming don't know why mind just stops giving any output and goes on a different trip
@manju-ep7nj
@manju-ep7nj 3 жыл бұрын
Sir, thank you for sharing your awesome information
@KyleHarrisonRedacted
@KyleHarrisonRedacted 3 жыл бұрын
I mean.. this is just implementing loops yourself, the only difference is the function requires scalar values to work from instead of expressions And the following streams example uses a functional loop with. ForEach These kinds of interview questions make me nervous because they're often asking you to do the worst, least efficient, and most terribly annoying way to solve a programming problem with pants-on-head style unrealistic restrictions Like kids asking "who'd win? Batman but he's in a wheel chair and missing his left arm and right leg, OR superman but he's just eaten kryptonite cereal for breakfast that day and broke every one of fingers as well he's just heard the news that his dog just died"
@mohamedsulaimaansheriff9787
@mohamedsulaimaansheriff9787 3 жыл бұрын
Recursion🔥🔥🔥
@dmatscheko
@dmatscheko 3 жыл бұрын
System.out.println("1 to 100 Without Using Any Loop in Code using recursive function and java streams."); There.. prints exactly what was asked ;)
@Howltusk
@Howltusk 3 жыл бұрын
would i still get it right if i just typed each number manually 🧐
@RSTPhysics
@RSTPhysics 3 жыл бұрын
Can also call recursive function first and print afterwards and decrease num for each instead and check if less than 1 as a exit statement, that way you can specify maximum number as a input right away. Sorry for python ;) def printnum(num): if num > 0: printnum(num-1) print(num) printnum(100)
@phlox22
@phlox22 3 жыл бұрын
Damn how can I forget Recursive method 😭
@GemaPratamaAditya
@GemaPratamaAditya 3 жыл бұрын
my very stupid way to answer this question: System.out.println("1"); System.out.println("2"); System.out.println("3"); System.out.println("4"); ... System.out.println("100"); there. no loops.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Now print 1 to 10000. ;)
@shaikhshahbaz7013
@shaikhshahbaz7013 3 жыл бұрын
@@naveenautomationlabs 😂😂😂
@debashishrath9541
@debashishrath9541 3 жыл бұрын
If 1 to 1000 needs to be printed and in this way it's done, then situation be like: Khataaam...tata...bye bye....😆😆😆😆🤣🤣🤣
@gregorymorse8423
@gregorymorse8423 3 жыл бұрын
@@naveenautomationlabs try printing 1 to 100000 with recursion and overflow the stack. The recursion method is even worse. Better would be to use C style macros to expand the code out 1 to n times
@AssassinGamer
@AssassinGamer 3 жыл бұрын
@@naveenautomationlabs for (int i = 0; i
@ranselynigrel8714
@ranselynigrel8714 2 жыл бұрын
Getting StackOverflow Error with this solution .... however numbers are getting printed
@bardplaygames
@bardplaygames 3 жыл бұрын
my first instinct was a bit caveman: print("1") print("2") print("3") print("4") . . . print("100")
@khodis2002
@khodis2002 3 жыл бұрын
I see a python-semihuman here
@kophaziistvan6477
@kophaziistvan6477 3 жыл бұрын
Okay, the recursive one is a correct solution, although I don't like it because it will not work for larger numbers. Isn't forEach in stream API considered a for loop? Then let me paste my solution: System.out.println("1"); System.out.println("2"); System.out.println("3"); System.out.println("4"); System.out.println("5"); System.out.println("6"); System.out.println("7"); System.out.println("8"); System.out.println("9"); System.out.println("10"); System.out.println("11"); System.out.println("12"); System.out.println("13"); System.out.println("14"); System.out.println("15"); System.out.println("16"); System.out.println("17"); System.out.println("18"); System.out.println("19"); System.out.println("20"); System.out.println("21"); System.out.println("22"); System.out.println("23"); System.out.println("24"); System.out.println("25"); System.out.println("26"); System.out.println("27"); System.out.println("28"); System.out.println("29"); System.out.println("30"); System.out.println("31"); System.out.println("32"); System.out.println("33"); System.out.println("34"); System.out.println("35"); System.out.println("36"); System.out.println("37"); System.out.println("38"); System.out.println("39"); System.out.println("40"); System.out.println("41"); System.out.println("42"); System.out.println("43"); System.out.println("44"); System.out.println("45"); System.out.println("46"); System.out.println("47"); System.out.println("48"); System.out.println("49"); System.out.println("50"); System.out.println("51"); System.out.println("52"); System.out.println("53"); System.out.println("54"); System.out.println("55"); System.out.println("56"); System.out.println("57"); System.out.println("58"); System.out.println("59"); System.out.println("60"); System.out.println("61"); System.out.println("62"); System.out.println("63"); System.out.println("64"); System.out.println("65"); System.out.println("66"); System.out.println("67"); System.out.println("68"); System.out.println("69"); System.out.println("70"); System.out.println("71"); System.out.println("72"); System.out.println("73"); System.out.println("74"); System.out.println("75"); System.out.println("76"); System.out.println("77"); System.out.println("78"); System.out.println("79"); System.out.println("80"); System.out.println("81"); System.out.println("82"); System.out.println("83"); System.out.println("84"); System.out.println("85"); System.out.println("86"); System.out.println("87"); System.out.println("88"); System.out.println("89"); System.out.println("90"); System.out.println("91"); System.out.println("92"); System.out.println("93"); System.out.println("94"); System.out.println("95"); System.out.println("96"); System.out.println("97"); System.out.println("98"); System.out.println("99"); System.out.println("100");
@TravelMania2022
@TravelMania2022 3 жыл бұрын
Keep making more interesting videos on coding
@intrestingfacts6785
@intrestingfacts6785 3 жыл бұрын
Please make videos on data structures and algorithms
@charbelfayad506
@charbelfayad506 3 жыл бұрын
Your taskbar looks scary :)
@alpanakarmarkar2867
@alpanakarmarkar2867 3 жыл бұрын
Thumbnail is scarier
@subbaraogannavarapu7405
@subbaraogannavarapu7405 3 жыл бұрын
Commenting without starting video. We can use streams to solve this problem. Awesome work Naveen🙏
@nikhilraosanas2463
@nikhilraosanas2463 3 жыл бұрын
If i talk about C lang then we can use goto statement to print 1 to n numbers without any loop or any function which is using loop internally
@gregorymorse8423
@gregorymorse8423 3 жыл бұрын
Goto creates a loop if it jumps backwards. Though not a for or while one.
@yevheniibatiievskyi
@yevheniibatiievskyi 3 жыл бұрын
IntStream.range(startNumber, endNumber + 1).forEach(System.out::println); instead of Lambda
@immortalhuman7085
@immortalhuman7085 3 жыл бұрын
After using recursion for factorial , I now using for this 😂😂
@ajay2302ful
@ajay2302ful 3 жыл бұрын
Ha ha...same thought came to me😀
@Evolutionmine16
@Evolutionmine16 3 жыл бұрын
You could also just write 100 System.out.println() calls and hardcode in the numbers. Probably the most efficient algorithm lol
@simonmultiverse6349
@simonmultiverse6349 3 жыл бұрын
...but then you would need to write a program to write the text of the 100 System.out.println() calls. That means you'd be writing a program which wrote a program. Cooooooooool!
@GeorgeSukFuk
@GeorgeSukFuk 3 жыл бұрын
@@simonmultiverse6349 were already in a simulation so you're already a program writing a program
@simonmultiverse6349
@simonmultiverse6349 3 жыл бұрын
@@GeorgeSukFuk If you wanted another name, you could always choose "Lickadick."
@GeorgeSukFuk
@GeorgeSukFuk 3 жыл бұрын
@@simonmultiverse6349 my name is a play on the name of George stephanopoulos so that might not work as well, but thanks for the idea!
@BayernTime
@BayernTime 3 жыл бұрын
Could you also use a dynamic switch statement? Like a variable that increments and a case statement that also increments? I don’t know if switch statements are allowed to have dynamic cases?
@thenewone4812
@thenewone4812 3 жыл бұрын
Should I learn Java?or python is enough?
@arthurg5966
@arthurg5966 3 жыл бұрын
1. Print string(code) using for loop, System.out.println("1"); System.out.println("2"); ... System.out.println("n"); 2. Copy and paste this code(strings) in your code and run
@balachandar6206
@balachandar6206 3 жыл бұрын
😂
@vipul1192
@vipul1192 3 жыл бұрын
I see this I get thought of recursion
@gnsc
@gnsc 2 жыл бұрын
You're awesome bro.
@suprabathj7843
@suprabathj7843 3 жыл бұрын
Thank you, great content
@vinayakbhandage8319
@vinayakbhandage8319 3 жыл бұрын
Can u make a video on java streams completely.
@sainiranjan40
@sainiranjan40 3 жыл бұрын
Thank you Naveen :)
@biolinseeds3535
@biolinseeds3535 3 жыл бұрын
Foreach uses a loop internally. It's just syntactic sugar.
@deecee2204
@deecee2204 3 жыл бұрын
i have 2 ways 1, recursion 2, goto (old programs) 😁
@loknathshankar5423
@loknathshankar5423 3 жыл бұрын
How does the traceback work in java, shouldn't it unwind back to initial value?
@adjmonkey
@adjmonkey 3 жыл бұрын
No, because he prints before the recursive step. If he was to do something like println(return(printNum(++n))); then it would start at the at the top and come back down
@mayanknegi2471
@mayanknegi2471 3 жыл бұрын
Does these type of questions are really asked in interview? These looks trivial and no real use
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Ya why not? It's a basic example of recursion. Not every question has a real use case.
@maheshbabu9909
@maheshbabu9909 3 жыл бұрын
I faced yesterday only 😁
@kennymccormic7578
@kennymccormic7578 3 жыл бұрын
System.out.println(1); System.out.println(2); .... System.out.println(100); Generate it using vim macro.
@KP-ih1hm
@KP-ih1hm 3 жыл бұрын
Thank you Naveen
@suhasdoke1157
@suhasdoke1157 3 жыл бұрын
What is the use of this? If you use recursion , ultimately you are doing the loop. Because at machine level you are just using the goto operand. In fact recursion will be inefficient as it has to push all the 99 calls on stack and them pop them back and process
@pandudamera7211
@pandudamera7211 3 жыл бұрын
Thank you so much brother
@skaruts
@skaruts 3 жыл бұрын
This is the easiest question ever *public void main(string [] args) {* *System.out.println(1)* *System.out.println(2)* *System.out.println(3)* *System.out.println(4)* *System.out.println(5)* *System.out.println(6)* *System.out.println(7)* *System.out.println(8)* *System.out.println(9)* *System.out.println(10)* *System.out.println(11)* *System.out.println(12)* *System.out.println(13)* *System.out.println(14)* *System.out.println(15)* *System.out.println(16)* *System.out.println(17)* *System.out.println(18)* *System.out.println(19)* *System.out.println(20)* *System.out.println(21)* *System.out.println(22)* *System.out.println(23)* *System.out.println(24)* *System.out.println(25)* *System.out.println(26)* *System.out.println(27)* *System.out.println(28)* *System.out.println(29)* *System.out.println(30)* *System.out.println(31)* *System.out.println(32)* *System.out.println(33)* *System.out.println(34)* *System.out.println(35)* *System.out.println(36)* *System.out.println(37)* *System.out.println(38)* *System.out.println(39)* *System.out.println(40)* *System.out.println(41)* *System.out.println(42)* *System.out.println(43)* *System.out.println(44)* *System.out.println(45)* *System.out.println(46)* *System.out.println(47)* *System.out.println(48)* *System.out.println(49)* *System.out.println(50)* *System.out.println(51)* *System.out.println(52)* *System.out.println(53)* *System.out.println(54)* *System.out.println(55)* *System.out.println(56)* *System.out.println(57)* *System.out.println(58)* *System.out.println(59)* *System.out.println(60)* *System.out.println(61)* *System.out.println(62)* *System.out.println(63)* *System.out.println(64)* *System.out.println(65)* *System.out.println(66)* *System.out.println(67)* *System.out.println(68)* *System.out.println(69)* *System.out.println(70)* *System.out.println(71)* *System.out.println(72)* *System.out.println(73)* *System.out.println(74)* *System.out.println(75)* *System.out.println(76)* *System.out.println(77)* *System.out.println(78)* *System.out.println(79)* *System.out.println(80)* *System.out.println(81)* *System.out.println(82)* *System.out.println(83)* *System.out.println(84)* *System.out.println(85)* *System.out.println(86)* *System.out.println(87)* *System.out.println(88)* *System.out.println(89)* *System.out.println(90)* *System.out.println(91)* *System.out.println(92)* *System.out.println(93)* *System.out.println(94)* *System.out.println(95)* *System.out.println(96)* *System.out.println(97)* *System.out.println(98)* *System.out.println(99)* *System.out.println(100)* *}*
@aonodensetsu
@aonodensetsu 3 жыл бұрын
My solution would be hardcoding since that's the only method that truly does not use loops Also recursion without the if loop inside of it - but recursion is looping so i'd call it a half-solution. There is no declared loop but the program loops itself.
@vamsikrishna2329
@vamsikrishna2329 3 жыл бұрын
Don't you think for each is still a loop?
@khodis2002
@khodis2002 3 жыл бұрын
Is this ment to he hard? It doesn't seem like that
@Aks-gj1kp
@Aks-gj1kp 3 жыл бұрын
How is foreaach not a loop, not directly but its still kind of a loop.
@bin_underscore
@bin_underscore 3 жыл бұрын
Thank you Naveen.
@balachandar6206
@balachandar6206 3 жыл бұрын
Recursion type creating stack over flow error Bro.....how to encounter it pls..😭
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
You need to break the condition in your logic to come out of recursion.
@Omikoshi78
@Omikoshi78 3 жыл бұрын
Can’t use “for loop” proceeds to use foreach. Next challenge, avoid using rcx register.
@satyamkaushik4467
@satyamkaushik4467 3 жыл бұрын
Thank you sir !!
@gorilladisco9108
@gorilladisco9108 3 жыл бұрын
eh .. what about "it's work so it's not stupid" method? the one that print it right away?
@venkateshmuvvala9336
@venkateshmuvvala9336 3 жыл бұрын
Void main() {Int k=0; Printed("%d ",k++); If (k=100) Exit(); Else Main() }
@isacnordin8048
@isacnordin8048 3 жыл бұрын
If recursion is allowed is map allowed (python code) Def print_elements(x): Print(x) Return x Map(print_elements,range(1,100+1))
@sriramkukkadapu
@sriramkukkadapu 3 жыл бұрын
ForEach is also a kind of loop so not relevant solution(question can be corrected)
@fatimaanser9074
@fatimaanser9074 3 жыл бұрын
Print 1 to 100 numbers using switch statement only in java....can any one help plz...
@PROJECTMartin
@PROJECTMartin 3 жыл бұрын
I would just copy and paste the print statement 100 times, saves memory on the stack
@Strakester
@Strakester 3 жыл бұрын
My first thought was: write a loop that outputs 100 print statements, then copy paste them into the code. It technically doesn't break the rules!
@Stickifican
@Stickifican 3 жыл бұрын
Set x = 1, print x, then x++. Copy and paste the print and x++ 99 times, and done.
@nagasailakshmi1767
@nagasailakshmi1767 3 жыл бұрын
Thank you naveen
@tsv0101
@tsv0101 3 жыл бұрын
I think foreach is a type of for loop right
@pvgr0007
@pvgr0007 3 жыл бұрын
Wow awesome 😎😎😎
@angatpatil3756
@angatpatil3756 3 жыл бұрын
>>>range(1,101)
@re_flow
@re_flow 3 жыл бұрын
Isn't foreach considered a for loop?
@sasaharukh8575
@sasaharukh8575 3 жыл бұрын
i think foreach is also considered as loop
@DineshKumar-wq8hn
@DineshKumar-wq8hn 3 жыл бұрын
You can use recursion to done it..
Find Duplicate Elements in An Array || Important Java Interview Questions
22:36
Naveen AutomationLabs
Рет қаралды 52 М.
Star Pattern Logic - Part 1 - By Naveen AutomationLabs
22:34
Naveen AutomationLabs
Рет қаралды 64 М.
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 21 МЛН
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 35 МЛН
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 354 М.
Print 1 To N Without Loop | School Practice Problems | Sadaf Khan
9:56
GeeksforGeeks School
Рет қаралды 4,1 М.
Interview Question: Print from 1 to 100 without using any numbers in your code
4:13
Tricky Interview Question: Maximum Number of Method Parameters Allowed in #Java
13:31
Learn JavaScript WHILE LOOPS in 8 minutes! 🔁
8:12
Bro Code
Рет қаралды 32 М.
Star Pattern Logic - Part 2 - By Naveen AutomationLabs
11:39
Naveen AutomationLabs
Рет қаралды 25 М.
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,4 МЛН
How To Explain Test Automation Framework In Interviews For Selenium
13:42
Why password should be stored in char array char[] instead of string?
9:19
Naveen AutomationLabs
Рет қаралды 51 М.
Durability test of Galaxy Note 8 vs S24 Ultra 😁 #galaxynote8 #s24ultra #iphonexr
0:28
Samsung® telefonlara dair herşey
Рет қаралды 15 МЛН
Did you know you can test a battery like this? 🪫🔋😳
0:13
scottsreality
Рет қаралды 1,6 МЛН
Куда пропал Kodak?
1:01
MOTIVESSION
Рет қаралды 13 МЛН
Wireless switch part 177
0:58
DailyTech
Рет қаралды 21 МЛН
Как изменилась цена этого ПК за 3 года?
0:36