Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Longhorn PHP 2021 - Passing the Technical Interview Workshop

Ben Edmunds
October 14, 2021
83

Longhorn PHP 2021 - Passing the Technical Interview Workshop

Ben Edmunds

October 14, 2021
Tweet

Transcript

  1. Who is this guy? Ben Edmunds Open Source Author PHP

    Town Hall Podcast More Than Code Podcast Sr Staff Eng @ Wayfair
  2. Stages 1. Phone Screen • High level • Why are

    you looking • What are you looking for • Pitch on company/role
  3. Stages • High level but deeper tech • Experience with

    specific technologies • Pitch on Company/Role 2. Manager Screen
  4. Stages 3. Coding Test - Take Home • Small project

    • Designing architecture • Designing APIs • Solving algorithms
  5. Stages 3. Coding Test - Online • Small problem(s) •

    Algorithmic problem • Time complexity • Space complexity
  6. Stages 3. Coding Test • Lite version of Coding and

    Sys Design on-site evals • Real world experience PREP
  7. Stages 3. Coding Test • Sys Design & Architecture •

    Based on role 
 interviewing for PREP
  8. Stages 3. Coding Test • Algos • Common Problems PREP

    + FizzBuzz, 8 Queens, Boggle, Subset Sum, etc
  9. Complexity O(N!) function factorial($n) { $factorial = 1; for ($i

    = 1; $i <= $n; $i++){ $factorial = $factorial * $i; } return $factorial; } for ($i = 0; $i <= factorial(8); $i++) { }
  10. Data Structures $l = new SplDoublyLinkedList; $l->push('a'); $l->push('b'); $l->push('c'); for

    ($l->rewind(); $l->valid(); $l->next()) { echo $l->current() . ', '; } => a, b, c
  11. Data Structures $l = new SplDoublyLinkedList; $l->push('a'); $l->push('b'); $l->push('c'); $list->rewind();

    echo $list->current() . ', '; $list->next(); echo $list->current() . ', '; $list->prev(); echo $list->current(); = > a, b, a
  12. Data Structures $hashMap = []; for ($i=1; $i<=10; $i++){ $hash

    = $i % 3; $hashMap[$hash] = isset($hashMap[$hash]) ? $hashMap[$hash] + $i : $i; } $hashMap[0] => 18
  13. Data Structures class Node { public $left, $right, $data; function

    __construct($data) { $this->data = $data; } }
  14. Data Structures class BST { public $rootNode; public function __construct($data=null)

    { if ($data !== null) { $this->rootNode = new Node($data); } }
  15. Data Structures public function search($data) { $node = $this->rootNode; while($node)

    { if ($data < $node->data) { $node = $node->left; } else if ($data > $node->data) { $node = $node->right; } else { break; } } return $node; }
  16. Algorithms fizz buzz Write a program that prints the numbers

    from 1 to 100 and for multiples of ‘3’ print “Fizz” instead of the number and for the multiples of ‘5’ print “Buzz”.
  17. Algorithms for ($i=1; $i<=100; $i++) { if ($i%3 === 0)

    { echo 'Fizz'; } else if ($i%5 === 0) { echo 'Buzz'; } else { echo $i; } }
  18. Algorithms single number Given a non-empty array of integers, every

    element appears twice except for one. Find that single one.
  19. Algorithms $input = [4, 1, 2, 1, 2]; $noDups =

    []; foreach ($input as $value) { $k = array_search($value, $noDups); if ($k === false) { $noDups[] = $value; } else { unset($noDups[$k]); } } echo $noDups[0];
  20. Algorithms $input = [4, 1, 2, 1, 2]; $noDups =

    []; foreach ($input as $value) { $k = array_search($value, $noDups); if ($k === false) { $noDups[] = $value; } else { unset($noDups[$k]); } } echo $noDups[0];
  21. Algorithms $input = [4, 1, 2, 1, 2]; $noDups =

    []; foreach ($input as $value) { $k = array_search($value, $noDups); if ($k === false) { $noDups[] = $value; } else { unset($noDups[$k]); } } echo $noDups[0];
  22. Algorithms $input = [4, 1, 2, 1, 2]; $noDups =

    []; foreach ($input as $value) { $k = array_search($value, $noDups); if ($k === false) { $noDups[] = $value; } else { unset($noDups[$k]); } } echo $noDups[0];
  23. Algorithms $input = [4, 1, 2, 1, 2]; $noDups =

    []; foreach ($input as $value) { $k = array_search($value, $noDups); if ($k === false) { $noDups[] = $value; } else { unset($noDups[$k]); } } echo $noDups[0];
  24. Algorithms $input = [4, 1, 2, 1, 2]; $hashmap =

    []; foreach ($input as $v) { $hashmap[$v] = isset($hashmap[$v]) ? $hashmap[$v]+1 : 1; } foreach ($hashmap as $k => $count) { if ($count === 1) { echo $k; break; } }
  25. Algorithms $input = [4, 1, 2, 1, 2]; $hashmap =

    []; foreach ($input as $v) { $hashmap[$v] = isset($hashmap[$v]) ? $hashmap[$v]+1 : 1; } foreach ($hashmap as $k => $count) { if ($count === 1) { echo $k; break; } }
  26. Algorithms $input = [4, 1, 2, 1, 2]; $hashmap =

    []; foreach ($input as $v) { $hashmap[$v] = isset($hashmap[$v]) ? $hashmap[$v]+1 : 1; } foreach ($hashmap as $k => $count) { if ($count === 1) { echo $k; break; } }
  27. Algorithms $input = [4, 1, 2, 1, 2]; $hashmap =

    []; foreach ($input as $v) { $hashmap[$v] = isset($hashmap[$v]) ? $hashmap[$v]+1 : 1; } foreach ($hashmap as $k => $count) { if ($count === 1) { echo $k; break; } }
  28. Algorithms $input = [4, 1, 2, 1, 2]; $hashmap =

    []; foreach ($input as $v) { $hashmap[$v] = isset($hashmap[$v]) ? $hashmap[$v]+1 : 1; } foreach ($hashmap as $k => $count) { if ($count === 1) { echo $k; break; } }
  29. Algorithms 8 queens Place eight queens on an 8×8 chessboard

    so that no two queens threaten each other; thus, a solution requires that no two queens share the same row, column, or diagonal.
  30. Algorithms public function run() : bool { // 8 to

    the power of 8 = // 16,777,216 possible board configurations $board = $this->generateBoard($hash); if (!$this->hasCollisions($board)) { return true; } $this->run($hash-1); }
  31. Algorithms interface SolverInterface { public function getBoard() : array; public

    function format() : string; public function hasCollision(int $row, int $col) : bool; public function run(int $col) : bool; } class NQueensSolver implements SolverInterface {}
  32. Algorithms $solver = new NQueensSolver(8); $solver->run(); $expectedBoard = [ [1,

    0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0] ]; echo 'Tests ' . ($solver->getBoard() === $expectedBoard ? 'passed 🎉' : 'failed 🚨');
  33. Algorithms $this->board = [ [0, 0, 0, 0, 0, 0,

    0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0] ];
  34. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  35. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  36. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  37. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  38. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  39. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  40. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  41. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  42. Algorithms public function run($col=0) : bool { // return true

    if we've iterated over the whole board if ($col >= $this->n) { return true; } // iterate over the rows for ($row = 0; $row < $this->n; ++$row) { if (!$this->hasCollision($row, $col)) { // place a queen $this->board[$row][$col] = 1; // check the next column to see if this worked if ($this->run($col+1)) { return true; } // this didn't work so let's remove the queen, backtrack, and try the next row $this->board[$row][$col] = 0; } } return false; }
  43. Algorithms public function hasCollision(int $row, int $col) : bool {

    // check the current row for ($thisCol = 0; $thisCol < $col; ++$thisCol) { if ($this->board[$row][$thisCol]) { return true; } } // check diagonally to the top left // no need to check the top right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisRow >= 0 && $thisCol >= 0; $thisRow--, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } // check diagonally to the bottom left // no need to check the bottom right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisCol >= 0 && $thisRow < $this->n; $thisRow++, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } return false; }
  44. Algorithms public function hasCollision(int $row, int $col) : bool {

    // check the current row for ($thisCol = 0; $thisCol < $col; ++$thisCol) { if ($this->board[$row][$thisCol]) { return true; } } // check diagonally to the top left // no need to check the top right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisRow >= 0 && $thisCol >= 0; $thisRow--, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } // check diagonally to the bottom left // no need to check the bottom right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisCol >= 0 && $thisRow < $this->n; $thisRow++, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } return false; }
  45. Algorithms public function hasCollision(int $row, int $col) : bool {

    // check the current row for ($thisCol = 0; $thisCol < $col; ++$thisCol) { if ($this->board[$row][$thisCol]) { return true; } } // check diagonally to the top left // no need to check the top right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisRow >= 0 && $thisCol >= 0; $thisRow--, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } // check diagonally to the bottom left // no need to check the bottom right since we're processing one column at a time for ($thisRow = $row, $thisCol = $col; $thisCol >= 0 && $thisRow < $this->n; $thisRow++, $thisCol--) { if ($this->board[$thisRow][$thisCol]) { return true; } } return false; }
  46. Algorithms time complexity Brute Force = O(nn) Backtracking = O(n!)

    https://en.wikipedia.org/wiki/Eight_queens_puzzle
  47. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:20 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  48. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  49. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  50. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  51. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  52. Examples “Given an array of the 100 most common child

    names in 2021, sort them alphabetically” “List the top 10 products sold alphabetically on the sidebar of a site. Given an array of the top 1,000 products where the key is their popularity and the value is the product name. Return an array.” Quicksort
  53. Examples “Given an array of the 100 most common child

    names in 2021, sort them alphabetically” Quicksort
  54. Examples “Given an array of the 100 most common child

    names in 2021, sort them alphabetically” const childNames = […]; return childNames.quicksort(); Quicksort
  55. Examples “List the top 10 products sold alphabetically on the

    sidebar of a site. Given an array of the top 1,000 products where the key is their popularity and the value is the product name. Return an array.” Quicksort
  56. Examples const products = […]; return products.quicksort() .slice(0, 10) .quicksort();

    “List the top 10 products sold alphabetically on the sidebar of a site. Given an array of the top 1,000 products where the key is their popularity and the value is the product name. Return an array.” Quicksort
  57. Examples const products = […]; return products.quicksort() .slice(0, 10) .quicksort();

    “List the top 10 products sold alphabetically on the sidebar of a site. Given an array of the top 1,000 products where the key is their popularity and the value is the product name. Return an array.” Quicksort
  58. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 2:30-3:20 - debrief w/ recruiter
  59. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 3:30-4 - debrief w/ recruiter
  60. Stages 4. Onsite Evals • 9-9:30 - arrival / meet

    recruiter • 9:30-10:20 - meet hiring manager • 10:30-11:20 - coding w/ 2 sr engineers • 11:30-12:30 - sys design w/ sr architect • 12:30-1:30 - lunch w/engineer on team • 1:30-2:20 - coding w/ 1 staff engineer • 3:30-4 - debrief w/ recruiter