Skip to content

Instantly share code, notes, and snippets.

@LWu93
LWu93 / currying.md
Last active August 12, 2020 19:57
currying.md

Currying


Interviewer Prompt (a)

Currying is the process by which a function of N arguments is implemented as N single-argument functions such that first of them takes in the first argument and returns a function which takes in the 2nd argument and so on, until the Nth single-argument function finally returns the value of the multi-argument function being implemented.

Your Task:

@LWu93
LWu93 / rainwaterCollector.md
Last active August 12, 2020 19:56
rainwaterCollector.md

Rain Water Collector

Prompt

You're an industrious programmer that lives off the grid. The local well that you use to fetch water has gone dry, so you've decided to collect rain water to filter; however, your collection device isn't flat.

You are given an array of non-negative integers representing an elevation map of the collection device where the width of each bar is 1. Write a function that determines how much water the map is able to hold.

Example

@LWu93
LWu93 / stringPermutations.md
Last active August 12, 2020 19:55
stringPermutations.md

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.

The array that is returned should only contain unique values and its elements should be in alphabetical order.

Examples

@LWu93
LWu93 / FandangoSystemDesign.md
Last active August 12, 2020 19:53
Fandango-I-SystemDesign.md

Background

System Design questions tests the candidate ability to be able to create a system based on a user prompt. A user prompt is either a client telling you what they want or a team making an assumption of what a potential user might want in an idea. What makes this different from an OOP Design question is that this focuses less on the application components themselves and more of the flow of data and how we scale that data based on our understanding of the various trade offs as we modify our system.

Design Fandango

User prompt: I want to be able to book movie theater seats online.

Design an API and a schema that may suit a movie ticket booking service.

@LWu93
LWu93 / balancedBrackets.md
Last active August 12, 2020 19:49
balancedBrackets

Prompt

Write a function that determines whether an input string has balanced brackets.

You are given an input string consisting of brackets—square [ ], round ( ), and curly { }. The input string can include other text. Write a function that returns either true if the brackets in the input string are balanced or false if they are not. Balanced means that any opening bracket of a particular type must also have a closing bracket of the same type.

An empty input string or a string without brackets is considered "balanced".

Examples

@LWu93
LWu93 / mergeTwoLinkedLists.md
Last active January 11, 2022 07:39
Merge Two Linked Lists

Merge Two Linked Lists

Interviewer Prompt

Write a function that takes in the heads of two Singly Linked Lists that are in sorted order. The function should merge the lists in place (i.e., it shouldn't create a brand new list) and return the head of the merged list in sorted order.

Each LinkedList node has an integer value as well as a next, pointing to the next node in the list or to null if it's the tail of the list.

LinkedList Node

@LWu93
LWu93 / stringSearch.md
Last active August 12, 2020 19:22
String Search REACTO

String Search

Prompt

Create a function that attempts to find the index of the first appearance of one string inside of another. If the substring exists, returns the beginning index of the substring. Otherwise return -1. You are essentially recreating the built in string method - indexOf().


Examples

@LWu93
LWu93 / uniquePaths.md
Last active June 5, 2020 22:04
Unique Paths Problem

Unique Paths

PROMPT

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

@LWu93
LWu93 / nthFibonacci.md
Last active June 4, 2020 15:42
Nth Fibonacci

Nth Fibonacci

PROMPT

The Fibonacci sequence is defined as follows: the first number of the sequence is 0, the second number is 1, and the nth number is the sum of the (n-1)th and (n-2)th numbers. Write a function that takes in an integer n and returns the nth Fibonacci number.

test cases

  • nthFib(6) //5 ->(0,1,1,2,3,5)
@LWu93
LWu93 / moveElementToEnd.md
Last active June 2, 2020 16:09
Move Element To End

PROMPT

You are given an array of integers and a target integer. Write a function that moves all instances of the target integer in the array to the end of the array. The order of the non-target integers in the array should be maintained.

Example

  • Input: ([2, 1, 2, 2, 2, 3, 4, 2], 2)
  • Output: [1, 3, 4, 2, 2, 2, 2, 2]

Interviewer Prompts:

Most will go toward the naive solution quickly. If they do, that's awesome. Once they get a solution, talk about time and space complexity and make sure they realize why the naive solution is O(n) (linear) space complexity. Then ask if they can create a solution without using any extra space, or an O(1) (constant) space. Watch out for value swapping in the array because this may lead to scrambled non-target numbers in our result array.