Coder Social home page Coder Social logo

ignacio-chiazzo / algorithms-leetcode-javascript Goto Github PK

View Code? Open in Web Editor NEW
560.0 10.0 82.0 343 KB

Algorithms resolution in Javascript. Leetcode - Geeksforgeeks - Careercup

Home Page: https://ignacio-chiazzo.github.io/Algorithms-Leetcode-Javascript/

License: MIT License

JavaScript 100.00%
leetcode-solutions leetcode leetcode-javascript algortithms interview-questions problemsolving javascript problem-solving computer-science interview-preparation

algorithms-leetcode-javascript's Introduction

Algorithms-Javascript

Solutions of algorithm problems using Javascript. https://ignacio-chiazzo.github.io/Algorithms-Leetcode-Javascript/

Structure

The solutions are located under /LeetcodeProblems. Each problem has a test file located under /LeetcodeProblemsTest.

Run Tests

Unit tests: To run all the test run node Test.js in the console. To run a specific problem in your console run node <problem_file_path> (e.g. node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js).

Linter: This repository uses es-lint. To run all the tests you would need to install the packages by running npm install followed by npx eslint LeetcodeProblems LeetcodeProblemsTests which will run the eslint in all problems and tests. You can also use the flag --fix which will automatically fix some of the errors.

Leetcode Problems

Name Level Link
Edit Distance Hard https://leetcode.com/problems/edit-distance/
Remove Invalid Parentheses Hard https://leetcode.com/problems/remove-invalid-parentheses/
Longest Consecutive Sequence Hard https://leetcode.com/problems/longest-consecutive-sequence/
Minimum Window Substring Hard https://leetcode.com/problems/minimum-window-substring/
Regular Expression Matching Hard https://leetcode.com/problems/regular-expression-matching/
NQueens Hard https://leetcode.com/problems/n-queens/
merge k sorted lists Hard https://leetcode.com/problems/merge-k-sorted-lists/
Set Matrix Zeroes Hard https://leetcode.com/problems/set-matrix-zeroes/
Subarray Sum Equals K Medium https://leetcode.com/problems/subarray-sum-equals-k/
3Sum Closest Medium https://leetcode.com/problems/3sum-closest/
3Sum Medium https://leetcode.com/problems/3sum/
NumberOfIslands Medium https://leetcode.com/problems/number-of-islands/
Swap Nodes in Pairs Medium https://leetcode.com/problems/swap-nodes-in-pairs/
Add Two Numbers Medium https://leetcode.com/problems/add-two-numbers/
Clone Graph Medium https://leetcode.com/problems/clone-graph/
Coin Change Medium https://leetcode.com/problems/coin-change/
Container With Most Water Medium https://leetcode.com/problems/container-with-most-water/
Design Circular Deque Medium https://leetcode.com/problems/design-circular-deque/
Escape The Ghosts Medium https://leetcode.com/problems/escape-the-ghosts/
Find All Anagrams in a String Medium https://leetcode.com/problems/find-all-anagrams-in-a-string/
Generate Parenthesis Medium https://leetcode.com/problems/generate-parentheses
Group Anagrams Medium https://leetcode.com/problems/group-anagrams/
Kth Largest Element in an Array Medium https://leetcode.com/problems/kth-largest-element-in-an-array/
Linked List Cycle II Medium https://leetcode.com/problems/linked-list-cycle-ii/
Longest Palindromic Substring Medium https://leetcode.com/problems/longest-palindromic-substring/
Longest Substring Without Reapeating Characters Medium https://leetcode.com/problems/longest-substring-without-repeating-characters
Max Area Of Island Medium https://leetcode.com/problems/max-area-of-island/
Max Consecutive Ones III Medium https://leetcode.com/problems/max-consecutive-ones-iii
Maximal Square Medium https://leetcode.com/problems/maximal-square/
Minimum Add to Make Parentheses Valid Medium https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/
Minimum Size Subarray Medium https://leetcode.com/problems/minimum-size-subarray-sum
Permutations Medium https://leetcode.com/problems/permutations/
Permutations II Medium https://leetcode.com/problems/permutations-ii/
Permutation in String Medium https://leetcode.com/problems/permutation-in-string/
Permutations Without Duplicates Medium https://leetcode.com/problems/permutations/
Restore IP Addresses Medium https://leetcode.com/problems/restore-ip-addresses/
SearchIng Rotated Sorted Array Medium https://leetcode.com/problems/search-in-rotated-sorted-array/
Search a 2D Matrix Medium https://leetcode.com/problems/search-a-2d-matrix/
Search a 2D Matrix II Medium https://leetcode.com/problems/search-a-2d-matrix/
Simplify Path Medium https://leetcode.com/problems/simplify-path/
Spiral Matrix Medium https://leetcode.com/problems/spiral-matrix/
Subsets Medium https://leetcode.com/problems/subsets/
Unique Binary Search Trees Medium https://leetcode.com/problems/unique-binary-search-trees/
Unique Paths Medium https://leetcode.com/problems/unique-paths/
Verify Preorder Serialization of a Binary Tree Medium https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/
Construct Binary Tree from Preorder and Inorder Traversal Medium https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
Lowest Common Ancestor of a Binary Tree Medium https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
Maximum Sum of an Hourglass Medium https://leetcode.com/problems/maximum-sum-of-an-hourglass/
Next Permutation Medium https://leetcode.com/problems/next-permutation/
Time Needed to Rearrange a Binary String Medium https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/
Find Subarrays With Equal Sum Medium https://leetcode.com/problems/find-subarrays-with-equal-sum/
Reverse Integer Medium https://leetcode.com/problems/reverse-integer/
Minimize Maximum Pair Sum in Array Medium https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/
Top K Frequent Elements Medium https://leetcode.com/problems/top-k-frequent-elements/
Gas Station Medium https://leetcode.com/problems/gas-station/description/
K Closest Points to Origin Medium https://leetcode.com/problems/k-closest-points-to-origin/
BestTimeToBuy Medium https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii
Flood Fill Easy https://leetcode.com/problems/flood-fill/
Implement stack using queues Easy https://leetcode.com/problems/implement-stack-using-queues/
Number of Segments in a String Easy https://leetcode.com/problems/number-of-segments-in-a-string/
Maximun Subarray Easy https://leetcode.com/problems/maximum-subarray
Min Stack Easy https://leetcode.com/problems/min-stack/
Reverse String II Easy https://leetcode.com/problems/reverse-string-ii/
Same Tree Easy https://leetcode.com/problems/same-tree/
Sum Of Square Numbers Easy https://leetcode.com/problems/sum-of-square-numbers/
Symmetric Tree Easy https://leetcode.com/problems/symmetric-tree/
Valid Parentheses Easy https://leetcode.com/problems/valid-parentheses/
Backspace String Compare Easy https://leetcode.com/problems/backspace-string-compare/
Binary Gap Easy https://leetcode.com/problems/binary-gap/
Majority Element Easy https://leetcode.com/problems/majority-element/
Longest Common Prefix Easy https://leetcode.com/problems/longest-common-prefix/
Two Sum Easy https://leetcode.com/problems/two-sum/
Tic Tac Toe Easy
Permutations With Duplicates Easy
Deletion Distance Easy
Award Budget Cuts Easy
Happy Number Easy https://leetcode.com/problems/happy-number/
Shuffle String Easy https://leetcode.com/problems/shuffle-string/

Sorting Algorithms

Algoritmhs
Heap Sort
Quick Sort

Databases

Problems Level Link
Trips and Users Hard https://leetcode.com/problems/trips-and-users/
Human Traffic of Stadium Hard https://leetcode.com/problems/human-traffic-of-stadium
Rank Scores Medium https://leetcode.com/problems/rank-scores
Consecutive Numbers Medium https://leetcode.com/problems/consecutive-numbers
Department Highest Salary Medium https://leetcode.com/problems/department-highest-salary
Exchange Seats Medium https://leetcode.com/problems/exchange-seats
Nth Highest Salary Medium https://leetcode.com/problems/nth-highest-salary
Combine Two Tables Easy https://leetcode.com/problems/combine-two-tables
Second Highest Salary Easy https://leetcode.com/problems/second-highest-salary
Customers Who Never Order Easy https://leetcode.com/problems/customers-who-never-order
Reformat Department Table Easy https://leetcode.com/problems/reformat-department-table
Employees Earning More Than Their Managers Easy https://leetcode.com/problems/employees-earning-more-than-their-managers/
Delete Duplicate Emails Easy https://leetcode.com/problems/delete-duplicate-emails
Rising Temperature Easy https://leetcode.com/problems/rising-temperature

UtilsClasses

Other languages provides built-in classes (e.g Linked List, Tree, etc). This module contains util classes to use in your problems.

Contributions

I'd be pleased to accept contributions. I'd be happy to discuss problems and solutions over a Pull Request or an Issue.

Each problem should have:

  1. A description of the problem at the top of the file.
  2. A test file with some test cases. The test file must export a test() function which should run all the tests of the file.
  3. An entry of the problem in the list of solutions within the README file.

PR Example: #39

algorithms-leetcode-javascript's People

Contributors

alucard2169 avatar anonimak avatar chaitra-bhat383 avatar deepesh85b avatar dependabot[bot] avatar dhaxor avatar hot9cups avatar ignacio-chiazzo avatar kav1239 avatar nbogie avatar ongzx avatar temitopeagbaje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithms-leetcode-javascript's Issues

Add the option to run lint and unit test locally.

The current repository uses a Github Action for running linters Github workflows

Add the option to run the linter locally by running commands. Optionally we can combine unit tests and lint and run them all in one command. There are also a few tests failing that should be updated.

Modifying Tests.js to handle multiple test exports

This is in response to the comment from my last PR.
I've been experimenting ever since, and I think there's a way it could be achieved.

What we want to do:

  1. For every problem, if we have multiple solutions, then we would like to have multiple test functions, one for each solution. This should help in debugging as well as is a cleaner and more maintainable way of writing code. We should also be free to name our test functions anything, as opposed to the rigid and undescriptive names(test or in some cases test1, test2, etc) we have right now,
  2. We want to modify Tests.js to be able to handle the test imports dynamically. Right now we hardcode it to invoke the test function as can be seen here. We want to get rid of this hardcoding as well as be able to invoke varying number of tests per test file as opposed to being able to invoke just 1 test per test file currently.

After having explored some of the options Javascript offers, I have found a solution to do this.
I'll be happy to work on the PR if you'd like to assign the issue to me.

Add a better pattern for each problem

Create a better pattern for problems:

  • Make sure each object implements its main function and export it.
  • Don't stop the main if any of the classes didn't implement the function
  • Put a warning with red letters whenever a problem wasn't added a main function
  • Fail test if a class doesn't implement main function an export it?

Create a structure for every problem like this? :

/* 
@param {string} a
@param {number} b
*/

var problemName = function(a,b...) {...}

var testCases = function() {
    console.log(problemName(...));
}

var main = function() {
   // print  something useful if needed
   testCases();
}

module.exports.main = main;

Add linters

It would be nice to add JS linters. Something basic to detect identation, spaces, and a few JS red flags

Idea: throw a unit test error if the problem doesn't have a test file nor an entry on the readme

We often have to request changes to PRs due to tests not being present or an entry to the readme isn't added.

I suggest we create a unit test that:
1- reads all the problem names and asserts there is a file for testing. We can do that by inspecting the problem's name and asserting there is a corresponding ${file_name}_test name with assert_ methods.
1- Reads the README and asserts there is a link to the problem created. This one is less important than the previous one.

Thoughts @hot9cups ?

Submit a Leetcode problem

Pick a problem in Leetcode or any other platform.

If you find a solution, follow the next steps:

Open A PR that contains:

  1. Solution in a file with a description of the problem at the top.
  2. A test file with some test cases. The test file must export a test() function which will run all the tests of the file.
  3. An entry of the problem in the list of solutions within the README file.

PR Example: #39

If you don't find a solution but want to discuss a problem, I would be happy to! In that case, please submit an issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.