This repository contains solutions to various technical interview problems implemented in JavaScript. Each problem is solved and tested to ensure correctness.
- Two Sums
- Max Consecutive Ones
- Longest Substring Without Repeating Characters
- Three Sums
- Valid Parentheses
- Valid Palindrome
- Winning Card
- Generate Sentence
- Sorted Squared
- Find First Non-Repeating Character Index
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!
Contributions to this project are welcome! If you would like to contribute, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and ensure that the tests pass
- Commit your changes and push them to your forked repository (following the Semantic Release approach)
- Submit a pull request describing your changes
- 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.
/**
* Name of the Problem
* Short Description
*
* @example
* solution('input data') -> 'expected return'
*/
const { deepEqual } = require("assert");
/**
* Time: O(n)
* Space: O(n)
* @param {String} str
* @returns {Boolean}
*/
function solution1(str) {
// Your code goes here
}
module.exports = () => {
// Test cases
{
deepEqual(solution1("valid input"), "expected to be true");
deepEqual(solution1("invalid input"), "expected to be false");
}
};
In the above code snippet, you can see the structure of how to create a new algorithm from scratch.
- Replace "Name of the Problem" with the actual name of the problem.
- Write a short description of the problem.
- Provide an example of the function call and the expected return value.
- Implement the solution inside the solution1 function.
- Test your solution by adding test cases inside the module.exports block using the deepEqual function to compare the actual output with the expected output.
- In your
index.js
file, make sure to import the newly added algorithm module.
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.
This project is licensed under the MIT License.