PayPal Interview Question: n= 20 for (i=0;i<n; i--) p... | Glassdoor

Interview Question

Software Engineer Intern Interview San Jose, CA

n= 20 for (i=0;i&lt;n; i--) print i the question was to

  change or replace a only one character in for loop to print 20 times.

Interview Answer

6 Answers


it has to do with decrement or condition clause in for loop

Interview Candidate on Apr 25, 2012

n= 20
for (i=0;-i

Anonymous on Apr 27, 2012

n= 20
for (i=0;i

Anonymous on Apr 27, 2012

add 4 in front of the 0 (in i=0); so it becomes i=40; i &lt; n (which is 20); i--

GK on May 22, 2012

changing i-- to n-- is a correct answer.

adding 4 in front of i=0 would work, but does not satisfy the condition "change or replace a character" as it adds a character instead.

big bad wolf on Oct 31, 2012

&lt; stands for '&lt;' and replace '-' with '+' for i in the increment part of for loop.

Siva Rama Krishna Ganta on Jul 3, 2019

Add Answers or Comments

To comment on this, Sign In or Sign Up.