Citigroup Interview Question for Java Developers


Team: Risk Management/CMOT
Country: India
Interview Type: In-Person




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

public static int fib(int n) {
	if(n<=1)
		return 1;
	else
		fib(n-1) + fib(n-2);
}

- Vaibhavs January 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great....
little correction:

public static int fib(int n) {
if(n<=1)
return 1;
else
return (ThreadTest.fib(n-1) + ThreadTest.fib(n-2));
}

- PKT April 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Optimize solution:

public void writeFibo(int num1, int num2, int count)
{
if(count <= 0)
{
return;
}
else
{
System.out.println("=>"+num2);
num2 = num1 + num2;
num1 = num2 - num1;
count--;
writeFibo(num1, num2, count);
}
}

- PKT April 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void fibanocci();
void main(){

//int y=1;
fibanocci(0,0);

}
void fibanocci(int t,int d){
int a=t+d;
if(a==0){
a=1;}/*
if(a>144000){
return;}*/
printf("%d\n",a);
fibanocci(d,a);

}

- reevus January 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void fibanocci();
void main(){

//int y=1;
printf("enter range of fibanocci");
int n;
scanf("%d",&n);
printf("0,");

fibanocci(0,0,n);
printf("\r");

}
void fibanocci(int t,int d,int n){
static int ky=0;

int a=t+d;
if(a==0){
a=1;}/*
if(a>144000){
return;}*/
printf("%d,",a);
ky++;
if(ky<n-1){
fibanocci(d,a,n);}
else {return;}
}

- rrrr January 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.*;
class fib
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int n=Integer.parseInt(str);
n=fib(n);
System.out.println("Fibb is "+n);
}
public static int fib(int n){
if(n==1 | n==0)return 1;
else return fib(n-1)+fib(n-2);

}}

- tg9963 January 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

fibonacci_series_recursive_method_dangerous(int n) {
    exit(0);
}

- Anonymous January 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.*;
class Solution
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int n=Integer.parseInt(str);
n=fib(n);
System.out.println("Fibb is "+n);
}
public static int fib(int n){
    if(n==1 | n==0)return 1;
    else return n + fib(n-1);
}

- Gaurav February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class A
{
public static void main(String[] args)
{
int f = 1 ;
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Any Value");
int x = sc.nextInt() ;
for(int i = 0; i<x; i++)
{
f = m1(x) ;

}
System.out.println(f);
}

private static int m1(int x)
{
int f = 1 ;
for(int i =x; i>0; i--)
{
f = f*i ;
}
return f;
}
}

- Anonymous February 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int fibonacciNum (int index)
	{
		 if(index <= 2)
			 return 1;
		 else
			 return fibonacciNum(index -1) + fibonacciNum(index -2);		
	}

- Beverley February 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

fibonacci(0,1);

void fibonacci(a,b){
  print b;
  fibonacci(b,a+b)
}

- Saudagar Mulik June 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int fib(int n) {
        if (n <= 1) {
            return n;
        }
        return fib(n - 2) + fib(n - 1);
    }

- Anonymous September 26, 2018 | 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