Skip to content

Instantly share code, notes, and snippets.

QuickSort

Interviewer prompt

Given a non-empty array of unique integers, sort the array in ascending order using the QuickSort algorithm.

What is QuickSort?

QuickSort is a popular and efficient sorting algorithm comparable to Merge Sort and Heap Sort. QuickSort is a recursive algorithm and consists of two major steps:

  1. Selecting a "pivot element".
  2. "Partitioning" elements in the array relative to selected pivot element.

String Permutations

Prompt

Given a string, return an array of all the permutations of that string. The permutations of the string should be the same length as the original string (i.e. use each letter in the string exactly once) but do not need to be actual words. As a reminder, a permutation of a string is another string containing all characters of the original string arranged in a different order.

The array that is returned should only contain unique values

Examples

Tree Traversals

Interviewer Prompt

Today you will write a couple of functions to implement Breadth First Search and Depth First Search tree traversals. IMPORTANT NOTE: The tree will NOT necessarily be a Binary Tree.

  • breadthFirst
  • depthFirstPreOrder

(If time allows, have your interviewee implement DFS Post Order traversal)

class: center middle

Reverse a Linked List

Interviewer Prompt

Given the head of a non-empty singly linked list of nodes with a property val (the value of the node) and a property next (a reference to the next node), reverse the order of the nodes. You do not need to worry about constructing the list. You may assume that the list has already been constructed for you. You may not create a new list, you must modify the original linked list and return the head of the reversed list.
FOLLOW UP: Can you solve the problem recursively/iteratively? (depending on which solution they came up with first.)

Definition of a Linked List Node

@EC7495
EC7495 / String Search.md
Last active June 24, 2020 19:52
String Search (needle in haystack)

class: center, middle

String Search

aka find the needle in the haystack. (Similar to JavaScript's indexOf but we are searching for an entire word as opposed to a single character)


Prompt

You are attempting to find the index of the first appearance of one string (the needle) inside of another (the haystack). You can think of the problem as looking for a particular substring inside another string and returning the starting index of that substring.