Interview Question


Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

recursion and printf i guess....

- Anonymous March 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

have a static variable and keep increment, print them from constructor . create array of 100 objects which will print 100. :-)

- howaboutthis March 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

100 printf statements in the simplest case. O(1) algorithm !

- Anonymous March 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's actually o(n) isn't it?

- Sumit March 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

#include<iostream>
using namespace std;

void Print( int n )
{
        cout << n;
        if(n<100)
        Print(n+1);
}

int main()
{
        Print(0);
return 0;
}

- Sasi March 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is not java

- Lesley Fang March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's actually o(n) isn't it

- Rampal March 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

one printf to write 1,2,3,4,5....100 or 100 printf will take O(1) but of no use
recursion is the only correct way to print this, I guess.

- PKT March 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int print(int n){
if (n==0){
return n+1;
}
print(n-1);
System.out.println(n);
return n;
}

- Saksham Dubey April 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class OutputWithoutLoop
{
public static void main(String[] args)
{
output(100);
}

public static void output(int number)
{
while(number > 0)
{
System.out.println(" number is :" + number);
number--;
}
}
}

- danqianchen April 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print1ToN(int n){
		if(n > 1){
			print1ToN(n-1);
		}
		System.out.println(n);
	}

- shaad May 01, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More