Skip to content

Explore JavaScript-based solutions for common technical interview problems and algorithms.

License

Notifications You must be signed in to change notification settings

danprates/algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tech Interview Problem Solving with JavaScript

This repository contains solutions to various technical interview problems implemented in JavaScript. Each problem is solved and tested to ensure correctness.

List of Problems

  1. Two Sums
  2. Max Consecutive Ones
  3. Longest Substring Without Repeating Characters
  4. Three Sums
  5. Valid Parentheses
  6. Valid Palindrome
  7. Winning Card
  8. Generate Sentence
  9. Sorted Squared
  10. Find First Non-Repeating Character Index

Usage

To run the tests for all problems, execute the following command:

npm run test

Feel free to explore each problem's solution and modify them as needed. Happy problem solving!

Debug

To debug the tests in the VSCode debugger, execute the following command: F5.

This will open the test runner in debug mode, allowing you to step through the code and inspect the values of variables.

Contributing

Contributions to this project are welcome! If you would like to contribute, please follow these steps:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and ensure that the tests pass
  4. Commit your changes and push them to your forked repository (following the Semantic Release approach)
  5. Submit a pull request describing your changes
  6. Please make sure to follow the existing code style and provide a clear description of your changes. Your contribution will be reviewed, and once approved, it will be merged into the main repository.

Style Guide

/**
 * Name of the Problem
 * Short Description
 *
 * @dificulty Easy
 * @example
 * solution('input data') -> 'expected return'
 */
import { deepEqual } from 'node:assert'
import { describe, test } from 'node:test'

/**
 * Time: O(n)
 * Space: O(n)
 * @param {String} str
 * @returns {Boolean}
 */
function solution1(str) {
  // Your code goes here
}

describe('Algorithm Name', () => {
  test('should return correct values', () => {
    const scenarios = [
      ['input', 'expected output'],
    ]

    for (const [str, expected] of scenarios) {
      deepEqual(solution1(str), expected)
    }
  })
})

In the above code snippet, you can see the structure of how to create a new algorithm from scratch.

  1. Replace "Name of the Problem" with the actual name of the problem.
  2. Write a short description of the problem.
  3. Provide an example of the function call and the expected return value.
  4. Implement the solution inside the solution1 function.
  5. Test your solution by adding test cases inside the describe block using the deepEqual function to compare the actual output with the expected output.

This template can be used as a starting point for solving new problems. Feel free to modify it according to the requirements of the problem you are working on.

License

This project is licensed under the MIT License.

About

Explore JavaScript-based solutions for common technical interview problems and algorithms.

Topics

Resources

License

Stars

Watchers

Forks