Skip to content

Instantly share code, notes, and snippets.

Variadic Curry

Prompt

'Curry' is a name for a utility function commonly employed in a functional programming context. Typically, the curry function takes in a function with arity N ('arity' simply means 'the number of arguments a function takes') and returns a function with an arity of 1.

When called, the returned function applies its argument to the original function, and then returns a new function with arity of one. When called, this returned function applies its argument, in turn, returning another function with an arity of one, and so on-- until all of the arguments have been passed in to the original function, at which point it is actually called and the actual result is returned.

We can manually curry funcitons without a currying utility function. For example:

Prompt

We are going to design our own code editor. For this exercise, we’ll assume that we are implementing this project using React and Redux. We are specifically interested in the design decisions we would make to allow users to manipulate the layout of various panels on their screen, and to keep track of user edits to their files.

Interviewees are encouraged to begin by drawing a diagram of what this code editor would look like.

Solution

These kinds of design questions are meant to foster a thoughtful conversation between you and your interviewer, and help your interviewer understanding how you approach and solve problems. By nature, they do not have a single correct answer. Therefore, the following offers just one of many possible solutions.

Intersection


Prompt

Given two sorted arrays of numbers, return an array containing all values that appear in both arrays. The numbers in the resulting array (the "intersection") may be returned in any order, they needn't be sorted.

You can assume that each array has only unique values (no duplicates within the array).

Slides


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.

@li-helen
li-helen / TreeTraversal.md
Last active June 19, 2019 21:48
Tree Traversal

Tree Traversal


Prompt

Today you will write a series of iterator functions for trees.

  • breadthFirst
  • depthFirstPreOrder