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))

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))

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))

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);
}

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))

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);
}

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);
}

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)

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);
}

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);
}

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);
}

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);
}

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 );
}
}

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;
}

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);
}

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;
}

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);
}

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;
}

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);}}

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);
}
}

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);
}

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.

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.