Sollicitatievraag

Sollicitatiegesprek voor de functie Android Developer

-Amsterdam

Booking.com

Write a function that would calculate a Pascal triangle element, given its coordinates.

Antwoord

Antwoorden op sollicitatievragen

7 antwoorden

0

Generally Pascal's triangle is considered to be 0-indexed, as it is based on combinations. public long Pascal(long n, long r) { if (r > n || r n) return Pascal(n, n - r); if (r == 0) return 1; return n * Pascal(n - 1, r - 1) / r; }

Anoniem op

0

private static int nCalc(int n,int k){ return factorial(n) / (factorial(k) * factorial(n-k)); } private static int factorial(int f){ int retval = 1; for (int i=1;i<=f;i++){ retval*=i; } return retval; }

Juan op

0

public static void main(String[] args) { int r = 5; for (int i = 1 ; i <= r; i ++) { int c = 1; for (int j = 1; j <= i; j ++) { System.out.print(c); c = c * (i - j) / j; } System.out.println(); } }

Tasneem op

0

public int getPascalElement(int row, int collumn) { if (collumn == 0 || collumn == row) { return 1; } return getPascalElement(row-1,collumn-1) + getPascalElement( row-1,collumn); }

Anoniem op

0

public static long triangleReturnCoordinate(int itemRow, int itemColumn) { long num = 1; if (itemColumn itemRow) { return -1; } else { for (int columnId = 0; columnId 0) { num = num * (itemRow - columnId) / columnId; } if (columnId == itemColumn - 1) { break; } } return num; } }

Anoniem op

0

This is how you print pascal triangle public void printPascalWithGivenInputs(int rows){ int noOfRows = rows; int noOfColumns = 2*noOfRows -1; int[][] pascalArr = new int[noOfRows][noOfColumns]; int middleIndex = noOfColumns/2; for(int outerIndex =0; outerIndex

Anoniem op

0

public static void triangle(int maxRows) { int r, num; for (int i = 0; i 0; j--) { System.out.print(" "); } for (int col = 0; col 0) { num = num * (r - col) / col; } System.out.print(num + " "); } System.out.println(); } }

Mohamed Gaber op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.