Domanda di colloquio di Amazon

code a function that takes 2 parameters and an algorithm, print out all the numbers between the 2 parameters that completes the algorithm

Risposte di colloquio

Anonimo

12 nov 2017

void foo(int a, int b, Func algo) { for(int i =a; i < b;i++) { if(algo(i)) { Console.WriteLine(i); } } }

Anonimo

12 nov 2017

The Signature of third parameter is not completely visible , dont know why. Its void foo(int a, int b, Func algo)

Anonimo

12 nov 2017

The Signature of third parameter is not completely visible , "Func algo"

Anonimo

22 ago 2018

We know that Function passes in 2 template types T and R. T extends Number/Integer and since the number is passed to the algorithm to check for completeness. If you define complete to be true false then R is Boolean or extends Boolean. If not then you have to ask for a definition of complete. Assuming completeeans boolean true then: void f(int a, int b, Function func) { int start = a

Anonimo

22 ago 2018

We know that Function passes in 2 template types T and R. T extends Number/Integer and since the number is passed to the algorithm to check for completeness. If you define complete to be true/false then R is Boolean or extends Boolean. If not then you have to ask for a definition complete. void f(int a, int b, Function func) { int start = a

Anonimo

26 set 2018

void Test(int a,int b, Func algo){ for(var i=a;i

Anonimo

29 gen 2019

@FunctionalInterface public interface Func { int calculate(Integer a, Integer b); } public class NoName { public static void main(String[] args) { Func func = (a,b) -> a+b; System.out.println(func(1, 2, func)); } static int func(final int a, final int b, Func func) { return func.calculate(a, b); } }