Interview Question


Country: United States




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

python code but I am sure you are looking for ideas:

def sum(x, max):
	if x == max:
		return max
	return x+sum(x+1, max)

print(sum(4, 7))

- aka March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python code but I am sure you are looking for ideas:

def sum(x, max):
	if x == max:
		return max
	return x+sum(x+1, max)

print(sum(4, 7))

- aka March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python code but I am sure you are looking for ideas:

def sum(x, max):
	if x == max:
		return max
	return x+sum(x+1, max)

print(sum(4, 7))

- aka March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int sum(int x, int max){
	if(max == x)
		return max;
	else
		return max + sum(x, max-1);
}

- Ishan March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python code but I am sure you are looking for ideas:

def sum(x, max):
	if x == max:
		return max
	return x+sum(x+1, max)

print(sum(4, 7))

- bap March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int sum(int x, int max){
	if(max == x)
		return max;
	else
		return max + sum(x, max-1);
}

- ishanshukla97 March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int sum(int x, int max){
		if(x==max)
		  return max;
		else 
			return x + sum(x+1,max);
	}

- Joey March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python one-line:

summ = lambda f, t: f if f == t else f + summ(f + 1, t)

- isRuslan March 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

JavaScript solution:

var sum = function(min, max) {
	if (min === max) {
		return max;
	}
	return min + countMachine(min + 1, max);
}

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

public int findRecursiveSum(int num, int maxNumber) {
		if (num == maxNumber)
			return num;
		else
			return num + findRecursiveSum(num + 1, maxNumber);
	}

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

public int findRecursiveSum(int num, int maxNumber) {
		if (num == maxNumber)
			return num;
		else
			return num + findRecursiveSum(num + 1, maxNumber);
	}

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

public static void calcSum(int from, int to, int sum) {

        sum = from + sum;

        if(from == to) {
            System.out.println(sum);
            return;
        }

        calcSum(from+1, to, sum);
    }

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

public class recursiveQtn {
    public recursiveQtn() {
        super();
    }

    public static void main(String[] args) {
        //recursiveQtn recursiveQtn = new recursiveQtn();
        int min; 
        min = new Integer(args[0]).intValue();
        int max;
        max = new Integer(args[1]).intValue();
        if (min>max)
            System.out.println("Min cannot be more than max"); 
        recursiveQtn mobj = new recursiveQtn();
        System.out.println(mobj.sum(min,max)); 
            
    }
    public int sum ( int min , int max )
         { if ( min == max ) 
             return min; 
            else 
               return max + sum (min , max-1 );
          }
}

- anjha March 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int recurcal(int x,int y){
if(x>y)
return 0 ;
return (x+(recurcal(x+1,y)));

}
int main(){
printf("%d",recurcal(4,7));
return 0;
}

- saurabh March 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int sum(int x, int max)
{
   return x > max ? 0 : x + sum(x + 1, max);
}

- ms March 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int rec_sum(int b, int e)
{
	if(b == e)
		return;
	else
		return (b + rec_sum(b + 1, e));
}

int main(int argc, char *argv[])
{
	int sum = rec_sum(1, 10);
	printf("Sum: %d\n", sum);
	return 0;
}

- rurtle March 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int sum(int x,int y)
{
if((y-x)==1)
return (x+y);
else
return x+sum(x+1,y);
}

- nawnit.sen7631 April 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int sum(static int x,static int max )
{
/* complete the code */
static int sum;
sum(sum + x++ + max--);
if(x>max)
return sum;
}

- Mookambika June 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

long sum(int x,int max){
static long res;
if(x>max)return res;
else{
res=res+x;
sum(x+1,max);}}

- Anuj July 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

long sum(int x,int max)
{
static long res;
if(x>max)return res;
else{
res=res+x;
sum(x+1,max);
}
}

- Anuj July 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int Sum(int,int);
int main()
{
int sum=Sum(4,7);
printf("Sum= %d",sum);
return 0;
}
int Sum(int a, int b){
if(a>b)
return 0;
else
return a+Sum(a+1,b);
}

- Anonymous October 01, 2016 | 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