Thursday, February 13th, 2020
Talk! The worst thing you can do is solve a problem in silence
Ask questions for clarification
DO NOT start coding right away; solve the problem first
Talk through your solution out loud
Make sure you solve the problem that you're given
Know that you won't solve everything
Interviewers will try to push you to the edge of what you're capable of, and that's okay!
You'll come up with a better solution afterwards on the (bus) ride home
Don't worry too much about syntax, unless you're told to
Choose your favourite language if you can
Once you're done, state complexity in big-O notation
Practice out loud
Tape a piece of paper on the wall and talk through a solution
Don't cheat!
Resources:
Cracking the Coding Interview (book)
Leetcode, HackerRank, ...
Things to know (at this point):
Strings, arrays, linked lists, stacks, queues, trees, graphs
Big-O, runtime and space complexity
Anything job-specific
Form a study group with your friends!
Useful and simple data structures
Some language-agnostic methods:
Stack: first in, last out
.push(Obj o) - add an object to the stack
.pop() - remove an object from the stack, or return null if the stack is empty
Queue: first in, first out
.enqueue(Obj o) - enqueue the given object
.dequeue() - dequeue the top object, or return null if queue is empty
[EASY] Write a program that prints the numbers from 1 to 70. For multiples of three print “Foo” instead of the number, and for the multiples of seven print “Bar”. For numbers which are multiples of both three and seven print “FooBar”.
Source: adapted from an interview at Gravit-E Technologies
Note: this question was made language-agnostic for this workshop. Originally, this question needed to be done in JavaScript, C#, or PHP.
Write a function to reverse a string. For example, given the string "abcde", the function should return "edcba".
Write a function that, given a number n, returns the n-th Fibonacci number.
Recall: the Fibonacci sequence is 1, 1, 2, 3, 5, 8, 13, ...
Source: interview for Later
You are given an unsorted array of (n-1) distinct integers in the range 1 to n. Write an algorithm to find the missing integer.
Source: CPSC 445
Given a 2D array composed only of the characters “R”, “G”, and “B”, return the index of the row that has the largest number of “R”s in it.
Assumptions: If the array is empty, or if no rows contain “R”s, return -1. You may assume that each row has the same length. If two rows are tied, return the first row (the lowest-indexed row).
Source: adapted from an interview at CA Technologies
You and your friend are Pokémon trainers. You two are teaming up to enter a tournament in which you must select only ONE Pokémon to fight for the both of you.
You are given two arrays of strings, where each string is a different type of Pokémon. The arrays are ordered in order of decreasing preference (1st = highest preference, last = lowest). Write an algorithm to return the name of the one Pokémon between you two that has the highest combined preference. If neither of you have a common Pokémon, you will use “Ditto”.
Source: adapted from a Yelp pre-screen