Solve this

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

Programming Puzzle - hot question asked in interview http://www.gufgaaf.com/Page/Di...

A_GuY · Jun 15, 2016 9:06 PM · 17,956 views

13 Replies

Easily can be done since modifying for loop is allowed. Just have i<101 and increase i by i=i+1 and print i. But this can be done without modifying the For loop. Just print ("1","2","3"......."100"); :)

BadhiJanne · Jun 15, 2016 9:50 PM

Yeah. But that prints 1 to 100 but we have to print 100 to 1.

A_GuY · Jun 15, 2016 10:14 PM

try this as well - http://gufgaaf.com/Page/Displa...

A_GuY · Jun 15, 2016 10:15 PM

Set I to 101 and decrease I to 1 or something like that.

Pharsi · Jun 15, 2016 11:04 PM

i'd do this in scripting for similar needs - I think the question asked to print 100 to 1: for(i=100; i>0; i--) { console.log(i); } and if you wanted 1 to 100: for(i=1; i<101; i++) { console.log(i); } wish all interview questions were as lame.

ghogay_moro · Jun 16, 2016 5:58 AM

@ghogay_moro Oops thats wrong.- everything needs to be done within for(var i=0){ } you cant start another for loop outside closing parenthesis. and you can't print 1 to 100.

A_GuY · Jun 16, 2016 7:21 AM

for(var i=0; i<100; i++) { console.log(100-i); }

c864916 · Jun 16, 2016 7:43 AM

c864916 - you got it.

A_GuY · Jun 16, 2016 9:26 AM

a_guy, i think i am not seeing the obvious. care to explain a bit how my for loop is "starting" outside&nbsp; either parentheses? not trying to be a deek, but just trying to understand which part of the question i misread. cheers! Last edited: 16-Jun-16 09:47 AM

ghogay_moro · Jun 16, 2016 9:46 AM

This is super basic. Calling it a Puzzle, itself is a Puzzle. Lol.

fuckeetow · Jun 16, 2016 9:58 AM

@ghogay_moro: What I understood was that the initializer expression should be limited to var i = 0. @A_GuY: Correct me if I am wrong. @fuckeetow: Yes, it's pretty straightforward. The only confusion folks had was with the initializer constraint.

c864916 · Jun 16, 2016 10:27 AM

thanks c88.., for the explanation. i can now wrap that in my head. the original question should have asked just that! side note: talking about interviews, i once helped prepare a question for an interview - to come up with a typewriter effect via ActionScript (Flash was a thing then!), and he didn't waste more than 3 minutes to complete it. it takes me more than 3 minutes to just think through the problem. some people really are good at what they do!

ghogay_moro · Jun 16, 2016 11:01 AM

Thanks guys for participating..

A_GuY · Jun 16, 2016 11:26 AM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all