Skip to content

A Typescript repository of my personal responses to several Leetcode questions, ready to run with Bun, including tests

Notifications You must be signed in to change notification settings

felipemullen/leetcode-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leetcode-questions

This is a typescript repository of my personal responses to several Leetcode questions.

Each question has their own subfolder, with the following content:

  • problem.md - The problem description as seen in leetcode
  • problem.test.ts - The test driver for the problem implementation
  • solution.ts - The implementation of the problem
  • files - Optional folder that may contain images or files needed to run the problem

Feel free to use this repository as a template to practice your own implementations 💻👾🖱️

Problem index

General Approach

Like my dad always used to say, there's many ways to skin a cat. I was never sure what that meant, but I can tell you that there are a great many ways to approach a coding problem.

I have a lot of experience in software, and I have my own passion project to focus on. So for the most part, I avoided spending more than 10-15 minutes per problem. This means some of the code will be sloppy, and a lot of solutions are not optimal.

That's ok. I am not John Carmac, just a lowly programmer.

Another Approach - Not enough time to code

Assume you are in a programming interview, but you are a mid level engineer, not an expert. You will be working in typescript only. For the problem below, perform the following steps, in order.

  1. Verbally explain the naive solution (e.g. to pick the Kth largest element, we could simply sort this array and pick the Kth element from the end) and why you wouldn't want to implement that.
  2. Explain an improved ideal solution as a better alternative
  3. Write down your proposed solution as lines of comments that will be eventually expanded into actual code. This should be a numbered list, where instead of writing code like myArray.At(-1) you would just write take the last element. For example:
1. iterate through the array
2. for each item, store the key in the map
3a. if the value is null, return
3b. if the value is 0, add to the map
  1. Write actual code by expanding the single line comments into actual code.
  2. Perform a dry-run and mention as many optimizations as possible.

Running a problem

The easiest way to run a problem is with Bun. All you need to do is run a test file directly, i.e.:

# Run a specific test
bun test 151_reverse-words/01-problem-151.test.ts

# Run all tests
bun test

# Run all tests and watch for changes
bun test --watch

If you don't have/want Bun, you're crazy you can use Node if you want, but you will either need to install tsc to compile the typescript and then run it directly, or install a package like ts-node to run it directly. If you feel like going down that path, check out the NodeJs typescript documentation page.

You will also have to change the test files to use a test package like jest instead of the built in bun helpers.

About

A Typescript repository of my personal responses to several Leetcode questions, ready to run with Bun, including tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •