## xyz Interview Question

• 0

Country: India

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

``````// ZoomBA
numbers = lfold( [2:n+1] , list(0,0,1) ) ->{
current_item = \$.p[-1] + \$.p[-2] + \$.p[-3]
\$.p += current_item
}``````

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

``````# Given a list of n numbers representing the first n elements of
# the sequence the kth-element of the sequence (k >= n+1) is
# given by the sum of the previous n elements in the sequence
# the method get_seq(n, generators) returns the first n elements
# of the sequence generated by the elements of the list generators

def get_seq(n, generators ) :
if n == 0 or len(generators) < 1:
print('Invalid input')
return

the_sequence = []
step = len(generators)
for i in range(0,len(generators)) :
the_sequence.append( generators[i])
print('step 0 el=%s' %the_sequence)
step = len(generators)

if step > n:
return generators[0:n]

while(step < n) :
next_element = 0
for i in range(0, len(generators)):
next_element += the_sequence[-1-i]
the_sequence.append(next_element)
step += 1
return the_sequence

#test
print(get_seq(14,[0,0,1,1]))``````

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

``````public static int lucas(int n)
{
int res[] = new int[n + 1];
for(int i = 0; i < res.length; i++){res[i] = -1;}
return lucas(n, res);
}

public static int lucas(int n, int res[])
{
if(res[n] != -1)
{
return res[n];
}else{

if(n == 0 || n == 1)
{
res[n] = 0;
return res[n];
}
if(n == 2)
{
res[n] = 1;
return res[n];
}

res[n] = lucas(n-1, res) + lucas(n-2, res) + lucas(n-3, res);
return res[n];
}
}

public static void main(String args[]){
for(int i = 0; i <= 10; i++)
{
System.out.println(lucas(i));
//0,0,1,1,2,4,7,13,24,44,81
}
}``````

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

``````package com.pubmatic.util;

public class Lucas {

public static void main(String[] args) {
Lucas lucas = new Lucas();
lucas.lucas(10);
}

private void lucas(int num) {
int thirdLast = 0;
int secondLast = 0;
int last = 1;
int current = 0;
System.out.print(thirdLast + "," + secondLast + "," + last + ",");
for (int i = 3; i < num; i++) {
current = last + secondLast + thirdLast;
System.out.print(current + ",");

int tmp = last;
last = current;
thirdLast = secondLast;
secondLast = tmp;
}

}

}``````

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

``````package com.pubmatic.util;

public class Lucas {

public static void main(String[] args) {
Lucas lucas = new Lucas();
lucas.lucas(10);
}

private void lucas(int num) {
int thirdLast = 0;
int secondLast = 0;
int last = 1;
int current = 0;
System.out.print(thirdLast + "," + secondLast + "," + last + ",");
for (int i = 3; i < num; i++) {
current = last + secondLast + thirdLast;
System.out.print(current + ",");

int tmp = last;
last = current;
thirdLast = secondLast;
secondLast = tmp;
}

}

}``````

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.