Slide 1

Slide 1 text

Preparing a Tech Interview

Slide 2

Slide 2 text

Preparing the Tech Interview: intro Big tech companies: - Google, Amazon, Facebook, Apple Online giants: - Booking, TripAdvisor, LinkedIn, PayPal, eBay, Dropbox, … Tech companies: - Red Hat, Oracle, Microsoft, LightBend, Cloudera, Elastic, ... We’ll focus on algorithms and data structures

Slide 3

Slide 3 text

Preparing the Tech Interview: complexity analysis Big O Notation a symbolism to describe the asymptotic behaviour of functions Examples: O(n·log n), O(2n) - it’s relative to the input: on x axis the input size, on y axis the time - it’s an upper bound - we’re interested only in the highest exponential: O(n2 + n2/2 + 100n) = O(n2)

Slide 4

Slide 4 text

Preparing the Tech Interview: complexity Algorithm Complexity Analysis

Slide 5

Slide 5 text

Preparing the Tech Interview: complexity Algorithm Complexity Analysis

Slide 6

Slide 6 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? int sum(int n) { if (n==0) { return 0; } return n + sum(n-1); }

Slide 7

Slide 7 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? Runtime complexity is O(n) int sum(int n) { if (n==0) { return 0; } return n + sum(n-1); }

Slide 8

Slide 8 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? Runtime complexity is O(n) And which is the space complexity? int sum(int n) { if (n==0) { return 0; } return n + sum(n-1); }

Slide 9

Slide 9 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? Runtime complexity is O(n) And which is the space complexity? Space complexity is O(1) int sum(int n) { if (n==0) { return 0; } return n + sum(n-1); }

Slide 10

Slide 10 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? int sum(int n) { int[] sums = new int[n+1]; sums[1] = 1; for (int i=2; i==n; i=+) { sums[i] = sums[i-1] + i; } return sums[n]; }

Slide 11

Slide 11 text

Preparing the Tech Interview: complexity examples int sum(int n) { int[] sums = new int[n+1]; sums[1] = 1; for (int i=2; i==n; i=+) { sums[i] = sums[i-1] + i; } return sums[n]; } Which is the runtime complexity of this method? Runtime complexity is O(n)

Slide 12

Slide 12 text

Preparing the Tech Interview: complexity examples int sum(int n) { int[] sums = new int[n+1]; sums[1] = 1; for (int i=2; i==n; i=+) { sums[i] = sums[i-1] + i; } return sums[n]; } Which is the runtime complexity of this method? And which is the space complexity? Runtime complexity is O(n)

Slide 13

Slide 13 text

Preparing the Tech Interview: complexity examples int sum(int n) { int[] sums = new int[n+1]; sums[1] = 1; for (int i=2; i==n; i=+) { sums[i] = sums[i-1] + i; } return sums[n]; } Which is the runtime complexity of this method? And which is the space complexity? Space complexity is O(n) Runtime complexity is O(n)

Slide 14

Slide 14 text

Preparing the Tech Interview: complexity examples int sum(int n) { int result = 1; for (int i=2; i==n; i=+) { result += i; } return result; } Which is the runtime complexity of this method?

Slide 15

Slide 15 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? Runtime complexity is O(n) int sum(int n) { int result = 1; for (int i=2; i==n; i=+) { result += i; } return result; }

Slide 16

Slide 16 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? And which is the space complexity? Runtime complexity is O(n) Runtime complexity is O(n) int sum(int n) { int result = 1; for (int i=2; i==n; i=+) { result += i; } return result; }

Slide 17

Slide 17 text

Preparing the Tech Interview: complexity examples Which is the runtime complexity of this method? And which is the space complexity? Space complexity is O(1) Runtime complexity is O(n) Runtime complexity is O(n) int sum(int n) { int result = 1; for (int i=2; i==n; i=+) { result += i; } return result; }

Slide 18

Slide 18 text

Preparing the Tech Interview: complexity examples int sum(int n) { return n * (n+1) / 2; } Which is the runtime complexity of this method?

Slide 19

Slide 19 text

Preparing the Tech Interview: complexity examples int sum(int n) { return n * (n+1) / 2; } Which is the runtime complexity of this method? Runtime complexity is O(1)

Slide 20

Slide 20 text

Preparing the Tech Interview: complexity examples int sum(int n) { return n * (n+1) / 2; } Which is the runtime complexity of this method? Runtime complexity is O(1) And which is the space complexity?

Slide 21

Slide 21 text

Preparing the Tech Interview: complexity examples int sum(int n) { return n * (n+1) / 2; } Which is the runtime complexity of this method? Runtime complexity is O(1) And which is the space complexity? Space complexity is O(1)

Slide 22

Slide 22 text

Preparing the Tech Interview: complexity examples void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n; i=+) { for (int j = 1; j < n; j=+) { if (array[j-1] < array[j]) { swap(array, j, j-1); } } } } Which is the runtime complexity of this method?

Slide 23

Slide 23 text

Preparing the Tech Interview: complexity examples void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n; i=+) { for (int j = 1; j < n; j=+) { if (array[j-1] < array[j]) { swap(array, j, j-1); } } } } Which is the runtime complexity of this method? Runtime complexity is O(n2)

Slide 24

Slide 24 text

Preparing the Tech Interview: complexity examples void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n; i=+) { for (int j = 1; j < n; j=+) { if (array[j-1] < array[j]) { swap(array, j, j-1); } } } } Which is the runtime complexity of this method? Runtime complexity is O(n2) And which is the space complexity?

Slide 25

Slide 25 text

Preparing the Tech Interview: complexity examples void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n; i=+) { for (int j = 1; j < n; j=+) { if (array[j-1] < array[j]) { swap(array, j, j-1); } } } } Which is the runtime complexity of this method? Runtime complexity is O(n2) And which is the space complexity? Space complexity is O(1)

Slide 26

Slide 26 text

Preparing the Tech Interview: complexity examples int fibonacci(int n) { if (n == 2) { return 1; } return fibonacci(n-1) + fibonacci(n-2); } Which is the runtime complexity of this method?

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Preparing the Tech Interview: complexity examples int fibonacci(int n) { if (n == 2) { return 1; } return fibonacci(n-1) + fibonacci(n-2); } Which is the runtime complexity of this method? Runtime complexity is O(2n)

Slide 29

Slide 29 text

Preparing the Tech Interview: complexity examples int fibonacci(int n) { if (n == 2) { return 1; } return fibonacci(n-1) + fibonacci(n-2); } Which is the runtime complexity of this method? Runtime complexity is O(2n) And which is the space complexity?

Slide 30

Slide 30 text

Preparing the Tech Interview: complexity examples int fibonacci(int n) { if (n == 2) { return 1; } return fibonacci(n-1) + fibonacci(n-2); } Which is the runtime complexity of this method? Runtime complexity is O(2n) And which is the space complexity? Space complexity is O(1)

Slide 31

Slide 31 text

Preparing the Tech Interview: what to study General Knowledge Data Structures: - Arrays - Trees, BST, Auto-Balancing Trees - Linked Lists - Maps - Stacks / Queues - Priority Queues / Heaps - Graphs

Slide 32

Slide 32 text

Preparing the Tech Interview: what to study General Knowledge Algorithms / Approaches: - Sorting (Quick Sort, Merge Sort, non-comparison Sort) - Trees (Pre-Order, In-Order, Post-Order) - Binary Search - Graph (DFS, BFS, Dijkstra) - Backtracking - Dynamic Programming - Computational Geometry

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Preparing the Tech Interview Let’s start with some interview questions

Slide 35

Slide 35 text

Preparing the Tech Interview: brain teaser? How many golf balls would fit in this room?

Slide 36

Slide 36 text

Preparing the Tech Interview: brain teaser? How many golf balls would fit in this room? - Golf ball radius is about 2.5cm - Sphere volume is: 4/3 · π · r3 - Golf ball volume is about 4/3 · 3.14 · 15 ~= 60 cm3

Slide 37

Slide 37 text

Preparing the Tech Interview: brain teaser? How many golf balls would fit in this room? - Golf ball radius is about 2.5cm - Sphere volume is: 4/3 · π · r3 - Golf ball volume is about 4/3 · 3.14 · 15 ~= 60 cm3 - This room is about 10m · 20m · 3m - Room volume is about 600 m3

Slide 38

Slide 38 text

Preparing the Tech Interview: brain teaser? How many golf balls would fit in this room? - Golf ball radius is about 2.5cm - Sphere volume is: 4/3 · π · r3 - Golf ball volume is about 4/3 · 3.14 · 15 ~= 60 cm3 - This room is about 10m · 20m · 3m - Room volume is about 600 m3 600 m3 / 60cm3 = 600 · 106 cm3 / 60cm3 ≈ 107 golf balls

Slide 39

Slide 39 text

Preparing the Tech Interview: brain teaser? There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly?

Slide 40

Slide 40 text

Preparing the Tech Interview: brain teaser? There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly? Label A O A+O A O A+O A A+O O O A+O A O A A+O A+O A O A+O O A

Slide 41

Slide 41 text

Preparing the Tech Interview: brain teaser? There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly? Label A O A+O A O A+O A A+O O O A+O A O A A+O A+O A O A+O O A

Slide 42

Slide 42 text

Preparing the Tech Interview: brain teaser? There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly? Label A O A+O O A+O A A+O A O

Slide 43

Slide 43 text

Preparing the Tech Interview: brain teaser? There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly? Label A O A+O O A+O A A+O A O Just pick from the box labeled A+O and you’re sure about all the labels.

Slide 44

Slide 44 text

Preparing the Tech Interview: references Online references ● www.topcoder.com - for gaining speed (and some useful tutorials) ● geeksforgeeks.org / leetcode.com - for detailed explanations of solutions ● www.codingame.com - for problems in gaming environment ● www.interviewbit.com - for following a gamificated program of practice ● pramp.com – for practicing real interviews with peers

Slide 45

Slide 45 text

Preparing the Tech Interview: live coding And now let’s start coding!