Interview Question: Print from 1 to 100 without using any numbers in your code

  Рет қаралды 487,460

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 774
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
One more solution: for 0 to 100: String s = "programmin"; int zero = s.length()-s.length(); int hundred = s.length() * s.length(); for(int i = zero; i
@sandipanmallick6141
@sandipanmallick6141 3 жыл бұрын
You are my Guru.... 🙏🙏
@skb7198
@skb7198 3 жыл бұрын
I think this should also work ... modified now for(int i='e' -'d'; i
@satishkrshnn
@satishkrshnn 3 жыл бұрын
Khatarnaak. Pranaam guru
@jeyhunaliyev1765
@jeyhunaliyev1765 3 жыл бұрын
including zero its awesome thanks a lot
@mislommislom9202
@mislommislom9202 3 жыл бұрын
Switch to python it is easier: for i in range(ord(e)): print(i)
@luisacuna8315
@luisacuna8315 3 жыл бұрын
I remember I got this question in one interview I had. My first thought was "Either this is a joke, or I'm not ready for this". Years later the solution seems so simple now. Very well done.
@taragnor
@taragnor 3 жыл бұрын
Well honestly it's a stupid question. I mean, it's asking you to program things in a weird impractical obtuse way. It'd be sort of like going for your drivers test and the instructor having you turn the wheel with your feet and operate the pedals with a long stick. Maybe it might be a decent question for intro hacking stuff, but that's about it.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Ya it was just asked in one of the interviews and we gave multiple solutions here.
@luisacuna8315
@luisacuna8315 3 жыл бұрын
@@taragnor agreed. Also when they give you complicated math Problems. Do you want me to code or become a physicist. Darling you can't have both
@munemshahariar2503
@munemshahariar2503 3 жыл бұрын
@@luisacuna8315 thats what i cant make them realize
@bolpol8085
@bolpol8085 3 жыл бұрын
@@taragnor It is a stupid question sure, But it also tests how well you know about programming and how computers work.
@pramodNavali
@pramodNavali 3 жыл бұрын
I thought of ASCII value, but the first solution really awesome.
@sakandchoudhary2941
@sakandchoudhary2941 3 жыл бұрын
that's Exactly what I was thinking of 😂
@katyayini8445
@katyayini8445 3 жыл бұрын
Me too..
@lupsik1
@lupsik1 3 жыл бұрын
Right on, first thought was ASCII value and then just ++ it edit : wait the solution in the video is exactly that lmao
@sholland42
@sholland42 3 жыл бұрын
Agreed, I thought ASCII too.
@William_Clinton_Muguai
@William_Clinton_Muguai 3 жыл бұрын
Exactly what I was thinking of.
@vladosononame6376
@vladosononame6376 3 жыл бұрын
When you want secure your code from understanding of classmates
@sumitgoyal385
@sumitgoyal385 Жыл бұрын
@@programaths itta serious nai hona bhai life me he just made joke
@devninja
@devninja 3 жыл бұрын
nice , but you used a number in 's1', just joking.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Hahaha that's a good catch 😭😭😭
@nihalnaughty911
@nihalnaughty911 3 жыл бұрын
@@naveenautomationlabs yeah🤣
@yaswanthyv3837
@yaswanthyv3837 3 жыл бұрын
Yeah really..
@Ammarkoka
@Ammarkoka 3 жыл бұрын
@@naveenautomationlabs yeah variable declaration s1 itni bhi kya zarurat padh gyi S k saath 1 lene ki 😂
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
@@Ammarkoka :)
@mukeshsiyak5623
@mukeshsiyak5623 3 жыл бұрын
Which company asks such questions. Companies i've encountered starts interview like "you are given a tree ......."
@sourabhchoudhary7289
@sourabhchoudhary7289 3 жыл бұрын
😂
@azhagurajaallinall126
@azhagurajaallinall126 3 жыл бұрын
And tell us more about your interview 😁 It may help others to prepare for their interviews
@kartikjoshi428
@kartikjoshi428 3 жыл бұрын
Lol true yrr..
@dailyinterestingshorts2964
@dailyinterestingshorts2964 3 жыл бұрын
Le me: i will plant it
@azhagurajaallinall126
@azhagurajaallinall126 3 жыл бұрын
@@dailyinterestingshorts2964 you mean planting a "tree" don't we just cut it down,because of its size
@Moonz97
@Moonz97 3 жыл бұрын
My solution is braindead I suppose lol. int zero = "".length(); int one = ".".length(); int hundred = Integer.valueOf(Integer.toString(one) + Integer.toString(zero) + Integer.toString(zero)); for(int i = one; i
@AndreasDelleske
@AndreasDelleske 3 жыл бұрын
Zero is still an int. Int is a number.
@Moonz97
@Moonz97 3 жыл бұрын
@@AndreasDelleske The way I understood the problem was to not use any number literals, i.e. 0-9 rather than not using any numeric types.
@otesunki
@otesunki 3 жыл бұрын
@@AndreasDelleske dude the for loop in the video LITERALLY USES AN INT int one = 'A'/'A';
@monochromeart7311
@monochromeart7311 3 жыл бұрын
@@AndreasDelleske also chars are numbers of 1 or 2 bytes, and the problem was not using any number literals.
@doomse150
@doomse150 3 жыл бұрын
@@AndreasDelleske The question was about number literals (the so called magic numbers when talking about code-style) and not numerical datatypes
@TheGermanRoxie
@TheGermanRoxie 3 жыл бұрын
Seems Naveen Automation Labs is the best thing ever Happened to QA Engineers.
@sharadsharma3176
@sharadsharma3176 3 жыл бұрын
I'm thinking of doing it with fork(). Remember it returns pid as 1, we can add bunch of forks to achieve our result.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
sounds interesting.
@ankgaur
@ankgaur 3 жыл бұрын
How fork()
@StefanReich
@StefanReich 3 жыл бұрын
@@tripplefives1402 That's so dirty and so clean at the same time
@bluediamond2309
@bluediamond2309 3 жыл бұрын
@@tripplefives1402 And what are we going to do with a ZerO ?
@SameerKumar-yu1xi
@SameerKumar-yu1xi 3 жыл бұрын
I also thought for this approach but was not exactly confident abt the exact ASCII value... But ye that is the appropriate that came into my mind when I saw scenario🖐️
@aniketsonawane9188
@aniketsonawane9188 3 жыл бұрын
Awesome 🔥
@FurquimRafa
@FurquimRafa 3 жыл бұрын
First thing that came to my mind for python was: Print(len("a")) Print(len("aa")) Print(len("aaa")) Print(len("aaaa")) ... And so on 😅
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
😂
@hotmole7621
@hotmole7621 3 жыл бұрын
Lol, but it works
@Nikolapestanac
@Nikolapestanac 3 жыл бұрын
Recursion for that is funnier since you just put an if with 100 a
@bubbleteaichooseyou
@bubbleteaichooseyou 3 жыл бұрын
That's technically correct
@arnavrawat9864
@arnavrawat9864 3 жыл бұрын
@@Nikolapestanac you can push 'a' into an array each time Have it print the length of an array This is really cool, but a stop mechanism is needed
@kivuosark2088
@kivuosark2088 3 жыл бұрын
This question should instantly click the concept that characters are stored as ASCII values. Pretty easy question.
@aflaqueahmad300
@aflaqueahmad300 3 жыл бұрын
It clicked but i dont remember the values lol
@sarthaksrthkyoutu100
@sarthaksrthkyoutu100 3 жыл бұрын
The question is of logic not memory
@excaliburofgachagames9241
@excaliburofgachagames9241 3 жыл бұрын
There is a question from my class I'd love to take a picture of. The students think that it is hard, I didnt even think to do that, like ever. I learned more from you than that said class btw.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad that you liked it :)
@bettercallbo
@bettercallbo 3 жыл бұрын
You could also use the args array And give the numbers as input at start. The rule only says that the numbers are not allowed in code
@max_208
@max_208 3 жыл бұрын
You would still have to retrieve the data from the args array.
@bettercallbo
@bettercallbo 3 жыл бұрын
@@max_208 yes but the numbers wouldn't be hardcoded The wording sounded to me that this was the rule
@tushar007kr
@tushar007kr 3 жыл бұрын
Awesome 😊👍 Ok one more possible solution for this... Static int i;//default 0 i++;// i=1 And later we can follow with ascii for setting limit 😊
@hassaanraheem5644
@hassaanraheem5644 3 жыл бұрын
Python Code : a = int(True) b = int(False) f_range = int(str(a) + str(b) + str(a)) for i in range(a,f_range): print(i)
@gerryiobbi9025
@gerryiobbi9025 3 жыл бұрын
wow, could you explain me please? I'm just a beginner in python!
@hamzapatel03
@hamzapatel03 3 жыл бұрын
@@gerryiobbi9025 a = int(True) returns integer 1 b = int(False) returns integer 0 f_range = int(str(a) + str(b) + str(a)) returns integer 101 Since you're a beginner, let me break it down for you str(a) returns "1" str(b) returns "0" str(a) returns "1" Now, if you concatenate these strings, you'd get a string which would be "101" because "1" + "0" + "1" returns "101" Now, all you need to do is type cast(convert the data type from one to another) this value i.e. int(str(a) + str(b) + str(a)) means int("101") which returns integer 101 Now, you can use a for loop to iterate through the values, for that he used the function range which essentially accepts two arguments, first is the starting integer which is a in our case, i.e. 1 and second is the ending integer which is f_range in our case, i.e. 101 Note: The ending integer is exclusive, meaning it won't be considered in the iteration i.e. our loop will iterate from 1 to 100 I'm assuming you'd know what print(i) does
@gerryiobbi9025
@gerryiobbi9025 3 жыл бұрын
@@hamzapatel03 Thank you so much!!! I really appreciated your explanation and I understood clearly :)
@samudraganguly6711
@samudraganguly6711 3 жыл бұрын
Nice one buddy
@sarthaksrthkyoutu100
@sarthaksrthkyoutu100 3 жыл бұрын
@@gerryiobbi9025 # Online Python compiler a =(True+True+True+True+True+True+True+True+True+True) a =a*a for i in range(True,a+True): print(i)
@akhileshhalkarni8192
@akhileshhalkarni8192 3 жыл бұрын
My solution : import java.math.BigInteger; public class ClassName{ public static void main(String[] args) { BigInteger s = BigInteger.ONE; int d = 'd'; int i = s.intValue(); while(i
@souvikchatterjee7400
@souvikchatterjee7400 3 жыл бұрын
Hey Naveen, this was a tricky but simple program and your solution was awesome. I faced similar situations where, I was asked to write a program and on that spot I wasn't able to give the proper solution. However after coming out of the interview, I thought about it for some time and I got a quick solution for it later. This happened to me couple of times. Could you please provide any suggestions how we can practice so that in such scenarios we can provide the solution quickly?
@sherlockholmes8096
@sherlockholmes8096 3 жыл бұрын
As an alternative for "one" you could declare variable as the static variable which would initialize it to 0 then increment it once before using inside the loop
@karthiiekeyan
@karthiiekeyan 3 жыл бұрын
using ASCII in python: for i in range( int(ord('a')/ord('a')), ord('d') ): print(i)
@thoperSought
@thoperSought 3 жыл бұрын
awesome, was looking for this. wouldn't you want ord('e'), tho?
@rohittester4669
@rohittester4669 3 жыл бұрын
we can do by it also ,for get max ,you can take any string for getting 100 String s="abc",s1="bcde",s2="jhkgj"; int min=s1.length()-s.length(); int max=s1.length()*s2.length()*s2.length(); for(int i=min;i
@VIK2000GEV
@VIK2000GEV 3 жыл бұрын
in C, I would solve it like this: #include int zero = ('a' == 'b'); int one = ('a' == 'a'); int sixty_four = sizeof(uint64_t) * sizeof(uint64_t); int thirty_two = sixty_four>>one; int four = sizeof(uint32_t); int hundred = sixty_four + thirty_two + four; // Rest is obvious
@vihaanfunandcrafts9851
@vihaanfunandcrafts9851 3 жыл бұрын
If you don't remember the ASCII values you can also use the diff (var - 'a'). This will give values 1 to 10 if var goes from b to k.
@Lhorez
@Lhorez 3 жыл бұрын
Another approach would be to take the ascii value of 'a' divided by itself for 1 and the ascii value of 'a' minus itself for 0. Then the rest can work itself out.
@shivajidandge6651
@shivajidandge6651 3 жыл бұрын
We can also do like this for(char c = 'A'%'A';c < 'd'; c++) { System.out.println(c+1); }
@abrar__jamadar
@abrar__jamadar 3 жыл бұрын
I got this as a recommendation and now am subscribed to your channel.
@LocherYT
@LocherYT 3 жыл бұрын
I googled for this because my buddy told me that came up in his interview for maintaining a starbucks logistic system. I originally thought this was an exercise for smartasses who memorized the entire ASCII table for fun but the first solution really proves how a programmer can and should be able to exert a certain amount of abstract thinking to get what he wants.
@bettyswunghole3310
@bettyswunghole3310 3 жыл бұрын
Interesting...I would have done it using ASCII values (but only because I've been looking at a bit of Assembler recently, and the idea of manipulating ASCII values to perform calculations is fresh in my mind!). Whether I would have been able to do it under under pressure in a job interview is an entirely different matter, however!
@Gaurav_Khurana
@Gaurav_Khurana 3 жыл бұрын
Good one... Very difficult to crack durong interview if the divide concept you dont know... I knew the ASCII part but did not knew.. Division of characters is possible
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
yes we can perform any arithmetic operations on characters : System.out.println('a' * 'b'); //9506 System.out.println('a' + 'b'); //195 System.out.println('a' - 'b'); //-1 System.out.println('a' / 'b'); //0
@k.ravichandra1049
@k.ravichandra1049 2 жыл бұрын
Thanks Naveen bro for covering this program.
@inigo8740
@inigo8740 3 жыл бұрын
I don't know if this is possible in Java, but in Python you can do int(True) to get 1, and the rest is easy.
@Techfly11
@Techfly11 3 жыл бұрын
Using True was my first thought as well.
@PoojaThakur-bp2tz
@PoojaThakur-bp2tz 3 жыл бұрын
This type of content is the reason you are the best guide for us🙏 What a video , it reminds me to brush up my ASCII knowledge 😁 Started practicing already 😁
@camelcasedsnivy
@camelcasedsnivy 3 жыл бұрын
There is even a way to do it without having integers in your code, without 100 prints. Just have an array of chars that represent every 1 digit number as a char. Then have a for loop and a nested for loop so that you could print i + j (if those are your variables)
@cedric1731
@cedric1731 3 жыл бұрын
I am not sure right now if this is also the case in Java but in C(++) true=1 and false=0. This means you could do something like: int i = (int) true + (int) true; i *= i; //4 i *= (i+(int) true)*(i+(int) true); //100 And then you do a normal for loop.
@gtg238s
@gtg238s 3 жыл бұрын
This can be done with Neo4J graph database where the nodes are numbers “one”, “two”, etc.. then write a query to retrieve and print the nodes in sequence
@conman698
@conman698 3 жыл бұрын
Technically, this is impossible as everything gets turned into binary which means that you are using numeric values regardless of what you program.
@joseville
@joseville 3 жыл бұрын
@Apple TV Define "the code"? The code is written in ascii which are numbers lol. The whole question is just ill defined and op makes a good point. It's not "obvious" at all. Total ambiguity. Besides, you're supposed to ask clarifying questions in an interview and this would be a good one.
@gohanvippi
@gohanvippi 3 жыл бұрын
Hi Naveen, one more way of printing came to my mind by manipulating default initialized value of class variable : public class NaveenJavaQuestion { static int a; public static void main(String[] args) { a++; int b = a; int c = (b+b+b+b); String s = Integer.toBinaryString(c); int d = Integer.parseInt(s); for(int i = b ; i
@c00Lify
@c00Lify 3 жыл бұрын
package main import ( "fmt" ) func main() { var x int x++ one := x two := one + one four := (two * two) five := four + one hundred := five * five * four for i := one; i
@Gruggo
@Gruggo 3 жыл бұрын
After seeing this video title, I decided to have a go before Watching. Having still not watched, C# makes this quite easy imo. Idk if this is in the spirit of the question though. char start = Char.MinValue; while (start < 'd') { start++; Console.WriteLine((int)start); }
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
good one, you made it very easy.
@Gruggo
@Gruggo 3 жыл бұрын
After watching, string lengths is a neat idea. I like that.
@mahalakshmikrishnadoss2272
@mahalakshmikrishnadoss2272 3 жыл бұрын
Ascii was my idea too... but 1st solution u r amazing naveen... 👏
@lizard450
@lizard450 3 жыл бұрын
Neat idea ... If someone asked me this in an interview I think I'd stop the interview.
@pakashvalarthasan8166
@pakashvalarthasan8166 3 жыл бұрын
I used to watch your videos without subscribe but after watching this I tapped on subscribe button
@akshaysapkale9136
@akshaysapkale9136 3 жыл бұрын
This goes same for me, I subscribed him !
@CerikNguyen
@CerikNguyen 3 жыл бұрын
One solution that doesnt use string is to initialize a variable a, then set the value of a = (int)&a. Since any address of a given that the program runs is not 0, you now have a non-zero variable. Divide a by itself and you got yourself a = 1, get b = 100 by whichever means you want using a and you have a solution without using strings. Note that by having an uinitialized variable also makes it non-zero sometimes, but obviously this doesnt work all the time.
@juanjose6091
@juanjose6091 3 жыл бұрын
I tried to solve it before watching the video. I thought we weren´t allowed to use int values, thus i came up with this solution: public class print{ public static void main(String args[]){ char let1 = 'a'; char let2 = 'a'; char let3 = 'e'; boolean freno = false; while(!freno){ System.out.println(let2 - let1); let2++; if( let2 - let1 == let3){ freno = true; } } } } I had to use the ASCII table for this. I believe that would be forbidden in an interview. However, if I come across this question in a real job interview, I will know how to solve it. Thank you so much :).
@aelithmackinnon8656
@aelithmackinnon8656 3 жыл бұрын
This is easy. Is_string("a string"), take the result of the function call and put it in a variable. Var++ and output var++ each loop. Stop the loop with a function call to size_of_string(typecastasstring(var)) when it is == size_of_string("abc"). Done.
@puneri743
@puneri743 3 жыл бұрын
Whoever asks such questions in the interview must be able to explain where and why he has to use such code. I always prefer to ask and to be asked the valid technical and logical questions and problems faced in our daily work. e.g. collections, design patterns, clean code, custom exception handling and so on.
@stormerthe2nd
@stormerthe2nd 3 жыл бұрын
Yeah lol i mean what could be the worst case where numbers wouldn't be allowed in a code
@MinecraftTestSquad
@MinecraftTestSquad 3 жыл бұрын
So before watching, and seeing it’s in Java... Primitive int values in Java default to 0, and the letter ‘d’ is ascii 100, sooo int start; int end = (int) ‘d’; do { start++; System.out.println(start); } while(start < end);
@Annihilated481
@Annihilated481 3 жыл бұрын
You're forgetting if this is in a function, "start" has to be initialized
@deveshnagawat1454
@deveshnagawat1454 3 жыл бұрын
With the basic knowledge of Python I did it using True and False value ie 1 & 0 and concatenated it str -> int then applied for loop with the range of True+False+True.
@chinmaynaik3962
@chinmaynaik3962 3 жыл бұрын
I am not good at Java syntax so here is one from me in python: for i in range(len("..........")**len("..")): print(i+len('.')) (** = Power)
@apmcd47
@apmcd47 3 жыл бұрын
I thought C and bitwise shift: int main(int argc, char **argv) { int acc, count; acc = ++count; // 1 acc
@TechLifeLabWorld
@TechLifeLabWorld 3 жыл бұрын
If you use some data structure, just initialize the structure, print the length and then, append whatever to the data structure and repeat, until length(string(data_structure.length))==length("ABC")
@gameglitcher
@gameglitcher 3 жыл бұрын
This is definitely a question to prompt questions based on how ambiguous it is. They are all literals so they are not actual numbers. It will need casting for the display lines, left the quote conversion out for readability. To abstract the digits out you would have to add a numeric operation of some sort. Now I ask if a string literal of digits is the same as a number, if they reply yes I don't want to work there anyways. for (char tens : " 123456789".toCharArray()) { if (tens != ' ') System.out.println(tens+'0'); for (char ones : "123456789".toCharArray()) { System.out.println(tens+ones); } } System.out.println("100"); I believe by using an integer variable and calculations you are violating the sanctity of the problem. You didn't "output the numbers 1 to 100 without using any numbers in your code" You indirectly assigned a number without using it's digits and proceeded to use that number to iterate and print the numbers from 1 to 100.
@Ellenki_007
@Ellenki_007 3 жыл бұрын
I am in love with for loop it's just cool.
@haileyen353
@haileyen353 3 жыл бұрын
(Written before watching video) With my limited apcsp knowledge... make a list, utilize appending items and list.length. probably gotta figure out how to loop it without numbers, but if all else fails, make it a function and copy/paste the function to cover 100 lines.
@dondigidon1633
@dondigidon1633 3 жыл бұрын
Naveen, it's great! Thank you 🎉🎉🎉
@DanijelTurina973
@DanijelTurina973 3 жыл бұрын
Since the terms of the task don't require the output to be *only* numbers 1 to 100, my solution in c is: #include #include int main() { int l = true; while(l) { printf("%i ",l); l++; } return 0; } Limiting it to 100 would require some fiddling.
@wristdisabledwriter2893
@wristdisabledwriter2893 3 жыл бұрын
A different approach that is similar to the first is instead of int one make it string s1=“*” and instead of I=one use I=s1.length and change the original s1 to s2
@stellarfirefly
@stellarfirefly 3 жыл бұрын
My first thought was that even the output should have no decimal digits in it, and thus would output the words, "one", "two", "three", etc. all the way up to "one hundred". So I came up with a solution that did this, which was of course much longer than the 2-3 line solutions in this video, but I feel was more practical. :)
@Annihilated481
@Annihilated481 3 жыл бұрын
A much simpler way is to make a while loop and check to see if the number as a string has a length of less than 3. int one = 'a' - 'a'; while (Integer.toString(one++).length() < "abc".length()) { System.out.println(one); }
@Ricocossa1
@Ricocossa1 3 жыл бұрын
I've tried it in C++ before watching the video. The way I did it is I got a zero by Xoring a variable with itself, which I'm pretty sure is what the interviewers wanted the guy to do. I cheated a little bit for 100. I don't know a lot about ascii, but I know ' ' is 10. So I cast it to an integer and multiplied it by itself.
@vikrantambekar3394
@vikrantambekar3394 3 жыл бұрын
Naveen thanks a lot Because of your Selenium Videos I got a Job in this pandemic situation I got Test Engineer profile Thanks a lot Naveen❤️❤️❤️
@welltypedwitch
@welltypedwitch 3 жыл бұрын
What a fun challenge. Here is my initial solution for haskell: one :: Int one = suc (getSum mempty) hundred = fromEnum 'd' main = traverse_ print [one..hundred] If you inline the definitions, you actually get a oneliner main = traverse_ print [suc (getSum mempty)..fromEnum 'd']
@Powerracer251
@Powerracer251 3 жыл бұрын
This question is kind of stupid. Considering that you still need to use integers to accomplish the task in some way, I'd be a smart ass and just recast a boolean as an integer and use ++. I technically am not using numbers there.
@AmulBhatia85
@AmulBhatia85 3 жыл бұрын
You put number of strings in array and take its length in to a variable and do increment on the variable by ++, Ot will solve your problem.. enjoy
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Can try with static int i (default value is 0): package JavaSessions; public class PrintOneToHundred { static int i; public static void main(String[] args) { /** * Output numbers from 1...100 * without using any numbers in your code. */ String s1 = ".........."; //10 dots i++; while(i
@Ellenki_007
@Ellenki_007 3 жыл бұрын
what's static here?
@vasanthanchinnasamy
@vasanthanchinnasamy 3 жыл бұрын
@@Ellenki_007 int i is static
@general.aladeeen
@general.aladeeen 8 ай бұрын
This is so good. Thanks man!
@divyavishwakarma2002
@divyavishwakarma2002 3 жыл бұрын
We can also use the concept of static variables as they get initialized with 0. And use them inside a recursive function which would check whether the number is less than the ASCII value of 'd'
@thegreatbambino3358
@thegreatbambino3358 3 жыл бұрын
Double for loop with ascii chars. A-Z and A-D. Print outer timed (Z-A) + inner minus A
@R.B.
@R.B. 3 жыл бұрын
You missed the obvious solution, Lambda Calculus. This was the best time to use Church Numbers if I've ever seen one.
@welltypedwitch
@welltypedwitch 3 жыл бұрын
But how are you going to print them without using digits in your string literals? :)
@R.B.
@R.B. 3 жыл бұрын
@@welltypedwitch Church Numbers don't use a string literal... At a basic level it is just counting. Zero() is usually null or false, true is One(), Two() is One() add One(), or true add true. Three is One() add One() add One(), etc. At some point you have a Church Number representation of a ascii code equivalent you can use for display purposes. Once you have the ascii code for AsciiZero(), then you can use Zero() add One() to be able to print "1". It's not like this would be less code, but it would be in some perspectives, pure.
@welltypedwitch
@welltypedwitch 3 жыл бұрын
​@@R.B. I know what church numbers are, but if you want to print them out you will still have to convert them to ascii somehow which really undermines the point of using church numerals in the first place (unless your language has a successor function for chars maybe, although that would still be a lot of work)
@R.B.
@R.B. 3 жыл бұрын
@@welltypedwitch point taken. My approach would be using advantage of the environment the program is running on once I utilized some side effect like printing to the screen. In theory you could go all the way, but arguably you'd have to leave the realm of LC you really satisfy the problem statement.
@ragavaanvesh
@ragavaanvesh 3 жыл бұрын
We can use big decimal constants.. for( BigDecimal i = BigDecimal.ONE ; i
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Yeah good one
@allysondossantossilva6875
@allysondossantossilva6875 3 жыл бұрын
What I used in JavaScript was pretty much your first solution, except that I didn't made an division but an .indexOf() to create the "1"
@pa8731
@pa8731 3 жыл бұрын
In Python 3: one = int(True) zero = int(False) Hundred = int(str(one)+str(zero)+str(zero)) for each in range(one, Hundred+one): print(each)
@shankumondal2881
@shankumondal2881 3 жыл бұрын
Ha ha ha .....😂 What a brilliant question . !!!! This is gonna my question when I am going to take any interview for our organization! 😁
@elikmtl
@elikmtl 9 ай бұрын
Thank you! You are the best!
@tarunmnair
@tarunmnair 3 жыл бұрын
Nice video. i've given this answer, before :- for(int i = ('b'-'a'); i
@gezamolnar5814
@gezamolnar5814 3 жыл бұрын
I like your solution a lot! Elegant and does beat around the bush. :) If you took advantage of operator precedence, one statement loop body and changed the loop variable right after printing it, you'd end up with something like this: for(int i = 'b'-'a'; i
@wattsonthetube
@wattsonthetube 3 жыл бұрын
Any points for actually printing the string "numbers from 1 to 100 without using any numbers in your code" - I mean I followed the instructions, because it's a string not a number and gave you the output you asked for. Other than that I maybe would have used a char '1' with a StringBuilder in a while loop and concatenated the characters together - but if it was without numbers (not data types) entirely I would have froze. Thanks for reminding me that you can use chars as ASCII, and can perform mathematical operations on them.
@simonmultiverse6349
@simonmultiverse6349 3 жыл бұрын
This is Python, where range(100) gives a list which starts at 0 and ends at 99. That's why I have to add two. two=len("a") ten=len("abcdeabcde") for five in range(ten*ten): print five+two
@phil2964
@phil2964 3 жыл бұрын
Amazing👍 hello from Russia🇷🇺
@herbert1557
@herbert1557 3 жыл бұрын
I use python to Solve it's easier just use the ord() function wich decode strings to ASCII representation wich are integers and then just define a one as ord("d")-ord("e"). Where d and e on ASCII are 100 and 101 respectively finally just make a simple for loop: Code: one = ord("e")-ord("d") Hundred = ord("e") for num in range(one,Hundred): print(num)
@manavsaxena5736
@manavsaxena5736 3 жыл бұрын
Woah !!!! It was so easy yet brain teasing for a first year student . How can I develop this sort of logical skills in programming ? I am in first year .
@Beatleman91
@Beatleman91 3 жыл бұрын
If a company gives me a task like that on the interview I'd stand up and walk out. When you hire a doctor do you ask him, if he can cook a human liver? No? So why you ask a programmer to perform something he'll never actually do on the job?
@spiritwolf448
@spiritwolf448 3 жыл бұрын
Simple solution in C: #include int main(void) { int x = 'a'-'a'; while (++x
@darlyson5235
@darlyson5235 3 жыл бұрын
Nice video man, my solution was in python: for c in range ("aaaaaaaaaa".count ("a") * "aaaaaaaaaa".count ("a") + "a".count ("a")): if c > "a".count ("b"): print (c)
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks for sharing!
@gerryiobbi9025
@gerryiobbi9025 3 жыл бұрын
Hi, I'm just a beginner in python. Could you explain me why you used an if statement here please? Thank you.
@darlyson5235
@darlyson5235 3 жыл бұрын
@@gerryiobbi9025 Hello Gerry, it's because the loop structure "for" begins from 0 (Zero), and the question requires from 1 to 100, the "if" statement tell to the computer to print the variable "c" only when variable "c" is bigger than 0, consequently the computer will print from 1 to 100.
@darlyson5235
@darlyson5235 3 жыл бұрын
"a".count ("b") will result in 0, because there's no "b" in "a"...
@gerryiobbi9025
@gerryiobbi9025 3 жыл бұрын
@@darlyson5235 Thank you so much for the explanation!!! :)
@rajanisuphari
@rajanisuphari 3 жыл бұрын
We can create a 100 char string, read char by char, append the char to a diff string and print the len of growing string, avoiding using int in code
@RezekYT
@RezekYT 3 жыл бұрын
My solution in python: for i in range(ord('e')): print(i)
@condesamel
@condesamel 3 жыл бұрын
That will start printing 0, won't it?
@RezekYT
@RezekYT 3 жыл бұрын
@@condesamel yeah, if you want to start with 1 you can change the range function with range(len('a'), ord('e')) for example
@calebfuller4713
@calebfuller4713 3 жыл бұрын
Python FTW: for i in range(int(not ''),ord('e')): print(i)
@thoperSought
@thoperSought 3 жыл бұрын
nice int(True) seems simpler, tho?
@calebfuller4713
@calebfuller4713 3 жыл бұрын
@@thoperSought True. Good one. I think my habit of using not came from code golfing in other languages where !a (or some undefined variable) would give 1, but yours is better in Python. ALTHOUGH... I realize now it can be a one-liner: print(*range(True,ord('e')),sep=' ') Let's see if someone can beat that! 😜
@thoperSought
@thoperSought 3 жыл бұрын
@@calebfuller4713 that's excellent, I love that. I always forget about sep
@rahul5481
@rahul5481 3 жыл бұрын
Thank for this video...What kind of data structure questions we can expect in interview in term of programming..can u please suggest
@sourestcake
@sourestcake 3 жыл бұрын
Here's my solution in C. Made it before looking at comments, so i did zero-initialization with static. I could've just used XOR on a local variable. Also this only works with ASCII, since it relies on 'd' having a decimal code of 100. You could also count up to that by using sizeof on an array, or doing stuff in Brainfuck-like increments. #include static int i; int main(int argc, char **argv) { for(++i; i
@iGalYaiR
@iGalYaiR 3 жыл бұрын
I thought you a solution using boolean values as binary values. Start from 1 (true) and go on by adding 1 (true) and shifting left until 100 is achieved (this can be done by saving 100 beforehand in a variable using bits)
@iGalYaiR
@iGalYaiR 3 жыл бұрын
@Apple TV Actually i thought of implementing it in python. After a quick google search it seems like there are bit manipulations operators in java.
@groverongo243
@groverongo243 3 жыл бұрын
Before watching the video: #include int x; int main(){ char c{'c'}; while(x!=c) std::cout
@sherwinvaz
@sherwinvaz 3 жыл бұрын
At first I was also confused how do I solve it then when he started coding I kinda got a clue and had a rough idea to progress using ascii. Pretty Impressive I hadn't come across such question nor did I know I could use out of box solution like this
@ivan8or
@ivan8or 3 жыл бұрын
i came up with: int a = Integer.MAX_VALUE - Integer.MAX_VALUE; while( (a+"").length() < 3){ System.out.println(++a); } using the ASCII table is pretty smart though :')
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Good one but you are using number 3 in your code.
@sayantandhara9099
@sayantandhara9099 3 жыл бұрын
We can type cast a boolean true into an integer which gives 1. This will be used for one
@anthonyjedi6998
@anthonyjedi6998 3 жыл бұрын
My first thought was KBReader and work off of that because they never said that you couldn’t input numbers plus it could be seen as being able to apply to more things
@ScorpioHR
@ScorpioHR 3 жыл бұрын
javascript version (it works): New version - more obfuscated: var _dot="."; function dash(dot) { let type = typeof dot; dot +=""; if(type === "number") console.log(dot); else dot = dot.length return dot; } function not(dot) {return dash(dash(dash(dot))) < dash("dot") ? not(dot+=_dot) : dot; } not(_dot);
@SidTheBot
@SidTheBot 3 жыл бұрын
Mylogic in Python: little messy print(*list(range(int(True),int(str(int(True)) + str(int(False)) + str(int(True))))))
@lekdo1285
@lekdo1285 3 жыл бұрын
Python: text1 = "p" one = len(p) text2 = "pppppppppp" ten = len(text2) for x in range(one, ten * ten + one): print(x)
@ritikajaiswal534
@ritikajaiswal534 3 жыл бұрын
Very nice and smooth way of doing this.. thanks!!
@mrswe4062
@mrswe4062 3 жыл бұрын
Create an enum with: zero, one and, two. Start for loop at index of one and end it when log(i) = index of two
@saintcorvic1194
@saintcorvic1194 3 жыл бұрын
This man is a genius. The first implementation is almost just as simple as using numbers.
@daniilorekhov9191
@daniilorekhov9191 3 жыл бұрын
My initial thought was doing something like int(True) to get a 1 and then use it to get 100 (1+1=2, 2*2*2=8, 2+8=10, 10*10=100)
@daniilorekhov9191
@daniilorekhov9191 3 жыл бұрын
Also, can use shifting bits after doing int(True) to get 2 and 8
Interview Question: Print Hello World without using semi colon (;) in Java
5:35
Naveen AutomationLabs
Рет қаралды 168 М.
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 28 МЛН
SISTER EXPOSED MY MAGIC @Whoispelagheya
00:45
MasomkaMagic
Рет қаралды 17 МЛН
Scenario Based Software Testing Interview Questions & Answers | Part 1
28:52
Software Testing Mentor
Рет қаралды 180 М.
Java Interview Question | One Of The Best Mock Interview For Freshers & Beginners | Kiran Sir
35:19
The Kiran Academy - Java By Kiran
Рет қаралды 357 М.
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,4 МЛН
SOLID  Principal - Interview Questions and Answers
24:04
Interview Happy
Рет қаралды 117 М.
Tricky Interview Question: Maximum Number of Method Parameters Allowed in #Java
13:31
Star Pattern Logic - Part 1 - By Naveen AutomationLabs
22:34
Naveen AutomationLabs
Рет қаралды 64 М.
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 28 МЛН