From 1410a149767ce5ac1ed3704bbd0657a215023233 Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 14:10:40 +0530 Subject: [PATCH 1/9] Added eslint --- .../Algorithms/K_Closest_Points_to_Origin.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js diff --git a/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js b/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js new file mode 100644 index 0000000..c92fde1 --- /dev/null +++ b/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js @@ -0,0 +1,46 @@ +/* +Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). + +The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). + +You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). + +Example 1 + +Input: points = [[1,3],[-2,2]], k = 1 +Output: [[-2,2]] +Explanation: +The distance between (1, 3) and the origin is sqrt(10). +The distance between (-2, 2) and the origin is sqrt(8). +Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin. +We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]]. + +Example 2: + +Input: points = [[3,3],[5,-1],[-2,4]], k = 2 +Output: [[3,3],[-2,4]] +Explanation: The answer [[-2,4],[3,3]] would also be accepted. +*/ + +/** + * @param {number[][]} points + * @param {number} k + * @return {number[][]} + */ + +var kClosest = function(points, k) { + const queue = []; + + for (let i = 0; i < points.length; i++) { + queue.push(points[i]); + queue.sort((a, b) => ((a[0] * a[0]) + (a[1] * a[1])) - ((b[0] * b[0]) + (b[1] * b[1]))); + + if (queue.length> k) { + queue.pop(); + } + } + + return queue; +}; + +module.exports.kClosest = kClosest; \ No newline at end of file From 426fb544428e509ea368345fca199ce8e8fd9423 Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 14:11:46 +0530 Subject: [PATCH 2/9] EsLint and Tests fix --- .../K_Closest_Points_to_Origin_Test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js diff --git a/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js b/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js new file mode 100644 index 0000000..f868bb5 --- /dev/null +++ b/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js @@ -0,0 +1,22 @@ +const assert = require('assert'); +var kClosest = require('../../LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin').kClosest; + +function test1() { + var points = [[1,3],[-2,2]] + var output = [[-2,2]] + assert.strictEqual(kClosest(points,1), output); +} + +function test2() { + var points = [[3,3],[5,-1],[-2,4]] + var output = [[-2,4],[3,3]] + assert.strictEqual(kClosest(points,2), output); +} + +function test() { + test1(); + test2(); +} + +module.exports.test = test + From d49b053e166c1f7325ec56a129dd9e39f6e8b1cc Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 14:16:20 +0530 Subject: [PATCH 3/9] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2014395..b9548f7 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil | [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | | [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | | [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ ### Sorting Algorithms | Algoritmhs | From a01edeebfe4b996065587570eb4efc2717d5deed Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 19:37:14 +0530 Subject: [PATCH 4/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9548f7..aa333f4 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil | [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | | [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | | [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ | [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | | [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | | [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | @@ -92,7 +93,6 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil | [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | | [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | | [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ ### Sorting Algorithms | Algoritmhs | From 0d38e479522c28d24bdab617d73675a45f6ed428 Mon Sep 17 00:00:00 2001 From: Chaitra Bhat Date: 2022年10月23日 20:05:43 +0530 Subject: [PATCH 5/9] Update README.md --- README.md | 136 +----------------------------------------------------- 1 file changed, 1 insertion(+), 135 deletions(-) diff --git a/README.md b/README.md index aa333f4..f2e8f80 100644 --- a/README.md +++ b/README.md @@ -1,135 +1 @@ -# 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 ` (e.g. `node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js`). - -**Linter:** This repository uses [`es-lint`](https://eslint.org/docs/latest/user-guide/command-line-interface). 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`](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems) which will automatically fix some of the errors. - -### Leetcode Problems - -| Name | Level | Link | -| - | - | - | -| [Edit Distance ](/LeetcodeProblems/Algorithms/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | -| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | -| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | -| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | -| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | -| [NQueens ](/LeetcodeProblems/Algorithms/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | -| [merge k sorted lists ](/LeetcodeProblems/Algorithms/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | -| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | -| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | -| [3Sum Closest](/LeetcodeProblems/Algorithms/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | -| [3Sum ](/LeetcodeProblems/Algorithms/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | -| [NumberOfIslands ](/LeetcodeProblems/Algorithms/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | -| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | -| [Add Two Numbers ](/LeetcodeProblems/Algorithms/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | -| [Clone Graph ](/LeetcodeProblems/Algorithms/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | -| [Coin Change ](/LeetcodeProblems/Algorithms/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | -| [Container With Most Water](/LeetcodeProblems/Algorithms/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | -| [Design Circular Deque ](/LeetcodeProblems/Algorithms/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ -| [Escape The Ghosts](/LeetcodeProblems/Algorithms/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | -| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | -| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | -| [Group Anagrams ](/LeetcodeProblems/Algorithms/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ -| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | -| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | -| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/| -| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters| -| [Max Area Of Island ](/LeetcodeProblems/Algorithms/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | -| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | -| [Maximal Square ](/LeetcodeProblems/Algorithms/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | -| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | -| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | -| [Permutations ](/LeetcodeProblems/Algorithms/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Permutations II ](/LeetcodeProblems/Algorithms/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | -| [Permutation in String](/LeetcodeProblems/Algorithms/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | -| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | -| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | -| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Simplify Path ](/LeetcodeProblems/Algorithms/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | -| [Spiral Matrix ](/LeetcodeProblems/Algorithms/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | -| [Subsets ](/LeetcodeProblems/Algorithms/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | -| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | -| [Unique Paths ](/LeetcodeProblems/Algorithms/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | -| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/Verify_Preorder_Serialization_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ | -| [Construct Binary Tree from Preorder and Inorder Traversal ](/LeetcodeProblems/Algorithms/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js) | Medium | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ | -| [Lowest Common Ancestor of a Binary Tree ](/LeetcodeProblems/Algorithms/Lowest_Common_Ancestor_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ | -| [Maximum Sum of an Hourglass](/LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | -| [Next Permutation](/LeetcodeProblems/Algorithms/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | -| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/Time_Needed_Rearrange_Binary_String.js)| Medium | https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/ | -| [Find Subarrays With Equal Sum ](/LeetcodeProblems/Algorithms/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | -| [Reverse Integer](/LeetcodeProblems/Algorithms/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | -| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | -| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | -| [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ -| [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | -| [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | -| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | -| [Maximun Subarray ](/LeetcodeProblems/Algorithms/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | -| [Min Stack ](/LeetcodeProblems/Algorithms/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | -| [Reverse String II ](/LeetcodeProblems/Algorithms/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | -| [Same Tree ](/LeetcodeProblems/Algorithms/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | -| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | -| [Symmetric Tree ](/LeetcodeProblems/Algorithms/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | -| [Valid Parentheses ](/LeetcodeProblems/Algorithms/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | -| [Backspace String Compare ](/LeetcodeProblems/Algorithms/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | -| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | -| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | -| [Majority Element](/LeetcodeProblems/Algorithms/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | -| [Longest Common Prefix](/LeetcodeProblems/Algorithms/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | -| [Two Sum](/LeetcodeProblems/Algorithms/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | -| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/Tic_Tac_Toe.js) | | | -| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/Permutations_With_Duplicates.js) | | | -| [Deletion Distance](/LeetcodeProblems/Algorithms/Deletion_Distance.js) | | | -| [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | -| [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | -| [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | - -### Sorting Algorithms -| Algoritmhs | -| - | -| [Heap Sort](/SortingAlgorithms/heapSort.js) | -| [Quick Sort](/SortingAlgorithms/QuickSort.js) | - -### Databases -| Problems | Level | Link | -|-|-|-| -| [Trips and Users](/LeetcodeProblems/Databases/Trips_and_Users.sql) | Hard | https://leetcode.com/problems/trips-and-users/ | -| [Human Traffic of Stadium](/LeetcodeProblems/Databases/Human_Traffic_of_Stadium.sql) | Hard | https://leetcode.com/problems/human-traffic-of-stadium | -| [Rank Scores](/LeetcodeProblems/Databases/Rank_Scores.sql) | Medium | https://leetcode.com/problems/rank-scores | -| [Consecutive Numbers](/LeetcodeProblems/Databases/Consecutive_Numbers.sql) | Medium | https://leetcode.com/problems/consecutive-numbers | -| [Department Highest Salary](/LeetcodeProblems/Databases/Department_Highest_Salary.sql) | Medium | https://leetcode.com/problems/department-highest-salary | -| [Exchange Seats](/LeetcodeProblems/Databases/Exchange_Seats.sql) | Medium | https://leetcode.com/problems/exchange-seats | -| [Nth Highest Salary](/LeetcodeProblems/Databases/nth_Highest_Salary.sql) | Medium | https://leetcode.com/problems/nth-highest-salary | -| [Combine Two Tables](/LeetcodeProblems/Databases/Combine_Two_Tables.sql) | Easy | https://leetcode.com/problems/combine-two-tables | -| [Second Highest Salary](/LeetcodeProblems/Databases/Second_highest_salary.sql)| Easy | https://leetcode.com/problems/second-highest-salary | -| [Customers Who Never Order](/LeetcodeProblems/Databases/Customers_Who_Never_Order.sql)| Easy | https://leetcode.com/problems/customers-who-never-order | -| [Reformat Department Table](/LeetcodeProblems/Databases/Reformat_Department_Table.sql) | Easy | https://leetcode.com/problems/reformat-department-table | -| [Employees Earning More Than Their Managers](/LeetcodeProblems/Databases/Employees_Earning_More_Than_Their_Managers.sql) | Easy | https://leetcode.com/problems/employees-earning-more-than-their-managers/ | -| [Delete Duplicate Emails](LeetcodeProblems/Databases/Delete_Duplicate_Emails.sql) | Easy | https://leetcode.com/problems/delete-duplicate-emails | -| [Rising Temperature](LeetcodeProblems/Databases/Rising_Temperature.sql) | 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: https://github.com/ignacio-chiazzo/Algorithms-Leetcode-Javascript/pull/39 + [Maximal Square ](/LeetcodeProblems/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ From ed79cdf3249df8fb1644626d417bbfce05052ab8 Mon Sep 17 00:00:00 2001 From: Chaitra Bhat Date: 2022年10月23日 20:34:52 +0530 Subject: [PATCH 6/9] updated readme --- .../Algorithms/K_Closest_Points_to_Origin.js | 90 ++++++------ .../K_Closest_Points_to_Origin_Test.js | 44 +++--- README.md | 136 +++++++++++++++++- readme.md | 136 +++++++++++++++++- 4 files changed, 337 insertions(+), 69 deletions(-) diff --git a/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js b/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js index c92fde1..fa2fca5 100644 --- a/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js +++ b/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js @@ -1,46 +1,46 @@ -/* -Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). - -The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). - -You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). - -Example 1 - -Input: points = [[1,3],[-2,2]], k = 1 -Output: [[-2,2]] -Explanation: -The distance between (1, 3) and the origin is sqrt(10). -The distance between (-2, 2) and the origin is sqrt(8). -Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin. -We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]]. - -Example 2: - -Input: points = [[3,3],[5,-1],[-2,4]], k = 2 -Output: [[3,3],[-2,4]] -Explanation: The answer [[-2,4],[3,3]] would also be accepted. -*/ - -/** - * @param {number[][]} points - * @param {number} k - * @return {number[][]} - */ - -var kClosest = function(points, k) { - const queue = []; - - for (let i = 0; i < points.length; i++) { - queue.push(points[i]); - queue.sort((a, b) => ((a[0] * a[0]) + (a[1] * a[1])) - ((b[0] * b[0]) + (b[1] * b[1]))); - - if (queue.length> k) { - queue.pop(); - } - } - - return queue; -}; - +/* +Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). + +The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). + +You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). + +Example 1 + +Input: points = [[1,3],[-2,2]], k = 1 +Output: [[-2,2]] +Explanation: +The distance between (1, 3) and the origin is sqrt(10). +The distance between (-2, 2) and the origin is sqrt(8). +Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin. +We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]]. + +Example 2: + +Input: points = [[3,3],[5,-1],[-2,4]], k = 2 +Output: [[3,3],[-2,4]] +Explanation: The answer [[-2,4],[3,3]] would also be accepted. +*/ + +/** + * @param {number[][]} points + * @param {number} k + * @return {number[][]} + */ + +var kClosest = function(points, k) { + const queue = []; + + for (let i = 0; i < points.length; i++) { + queue.push(points[i]); + queue.sort((a, b) => ((a[0] * a[0]) + (a[1] * a[1])) - ((b[0] * b[0]) + (b[1] * b[1]))); + + if (queue.length> k) { + queue.pop(); + } + } + + return queue; +}; + module.exports.kClosest = kClosest; \ No newline at end of file diff --git a/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js b/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js index f868bb5..3164742 100644 --- a/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js +++ b/LeetcodeProblemsTests/Algorithms/K_Closest_Points_to_Origin_Test.js @@ -1,22 +1,22 @@ -const assert = require('assert'); -var kClosest = require('../../LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin').kClosest; - -function test1() { - var points = [[1,3],[-2,2]] - var output = [[-2,2]] - assert.strictEqual(kClosest(points,1), output); -} - -function test2() { - var points = [[3,3],[5,-1],[-2,4]] - var output = [[-2,4],[3,3]] - assert.strictEqual(kClosest(points,2), output); -} - -function test() { - test1(); - test2(); -} - -module.exports.test = test - +const assert = require("assert"); +var kClosest = require("../../LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin").kClosest; + +function test1() { + var points = [[1,3],[-2,2]]; + var output = [[-2,2]]; + assert.strictEqual(kClosest(points,1), output); +} + +function test2() { + var points = [[3,3],[5,-1],[-2,4]]; + var output = [[-2,4],[3,3]]; + assert.strictEqual(kClosest(points,2), output); +} + +function test() { + test1(); + test2(); +} + +module.exports.test = test; + diff --git a/README.md b/README.md index f2e8f80..aa333f4 100644 --- a/README.md +++ b/README.md @@ -1 +1,135 @@ - [Maximal Square ](/LeetcodeProblems/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ +# 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 ` (e.g. `node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js`). + +**Linter:** This repository uses [`es-lint`](https://eslint.org/docs/latest/user-guide/command-line-interface). 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`](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems) which will automatically fix some of the errors. + +### Leetcode Problems + +| Name | Level | Link | +| - | - | - | +| [Edit Distance ](/LeetcodeProblems/Algorithms/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | +| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | +| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | +| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | +| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | +| [NQueens ](/LeetcodeProblems/Algorithms/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | +| [merge k sorted lists ](/LeetcodeProblems/Algorithms/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | +| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | +| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | +| [3Sum Closest](/LeetcodeProblems/Algorithms/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | +| [3Sum ](/LeetcodeProblems/Algorithms/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | +| [NumberOfIslands ](/LeetcodeProblems/Algorithms/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | +| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | +| [Add Two Numbers ](/LeetcodeProblems/Algorithms/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | +| [Clone Graph ](/LeetcodeProblems/Algorithms/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | +| [Coin Change ](/LeetcodeProblems/Algorithms/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | +| [Container With Most Water](/LeetcodeProblems/Algorithms/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | +| [Design Circular Deque ](/LeetcodeProblems/Algorithms/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ +| [Escape The Ghosts](/LeetcodeProblems/Algorithms/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | +| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | +| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | +| [Group Anagrams ](/LeetcodeProblems/Algorithms/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ +| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | +| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | +| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/| +| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters| +| [Max Area Of Island ](/LeetcodeProblems/Algorithms/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | +| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | +| [Maximal Square ](/LeetcodeProblems/Algorithms/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | +| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | +| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | +| [Permutations ](/LeetcodeProblems/Algorithms/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Permutations II ](/LeetcodeProblems/Algorithms/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | +| [Permutation in String](/LeetcodeProblems/Algorithms/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | +| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | +| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | +| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Simplify Path ](/LeetcodeProblems/Algorithms/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | +| [Spiral Matrix ](/LeetcodeProblems/Algorithms/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | +| [Subsets ](/LeetcodeProblems/Algorithms/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | +| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | +| [Unique Paths ](/LeetcodeProblems/Algorithms/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | +| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/Verify_Preorder_Serialization_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ | +| [Construct Binary Tree from Preorder and Inorder Traversal ](/LeetcodeProblems/Algorithms/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js) | Medium | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ | +| [Lowest Common Ancestor of a Binary Tree ](/LeetcodeProblems/Algorithms/Lowest_Common_Ancestor_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ | +| [Maximum Sum of an Hourglass](/LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | +| [Next Permutation](/LeetcodeProblems/Algorithms/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | +| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/Time_Needed_Rearrange_Binary_String.js)| Medium | https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/ | +| [Find Subarrays With Equal Sum ](/LeetcodeProblems/Algorithms/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | +| [Reverse Integer](/LeetcodeProblems/Algorithms/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | +| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | +| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | +| [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ +| [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | +| [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | +| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | +| [Maximun Subarray ](/LeetcodeProblems/Algorithms/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | +| [Min Stack ](/LeetcodeProblems/Algorithms/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | +| [Reverse String II ](/LeetcodeProblems/Algorithms/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | +| [Same Tree ](/LeetcodeProblems/Algorithms/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | +| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | +| [Symmetric Tree ](/LeetcodeProblems/Algorithms/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | +| [Valid Parentheses ](/LeetcodeProblems/Algorithms/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | +| [Backspace String Compare ](/LeetcodeProblems/Algorithms/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | +| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | +| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | +| [Majority Element](/LeetcodeProblems/Algorithms/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | +| [Longest Common Prefix](/LeetcodeProblems/Algorithms/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | +| [Two Sum](/LeetcodeProblems/Algorithms/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | +| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/Tic_Tac_Toe.js) | | | +| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/Permutations_With_Duplicates.js) | | | +| [Deletion Distance](/LeetcodeProblems/Algorithms/Deletion_Distance.js) | | | +| [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | +| [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | +| [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | + +### Sorting Algorithms +| Algoritmhs | +| - | +| [Heap Sort](/SortingAlgorithms/heapSort.js) | +| [Quick Sort](/SortingAlgorithms/QuickSort.js) | + +### Databases +| Problems | Level | Link | +|-|-|-| +| [Trips and Users](/LeetcodeProblems/Databases/Trips_and_Users.sql) | Hard | https://leetcode.com/problems/trips-and-users/ | +| [Human Traffic of Stadium](/LeetcodeProblems/Databases/Human_Traffic_of_Stadium.sql) | Hard | https://leetcode.com/problems/human-traffic-of-stadium | +| [Rank Scores](/LeetcodeProblems/Databases/Rank_Scores.sql) | Medium | https://leetcode.com/problems/rank-scores | +| [Consecutive Numbers](/LeetcodeProblems/Databases/Consecutive_Numbers.sql) | Medium | https://leetcode.com/problems/consecutive-numbers | +| [Department Highest Salary](/LeetcodeProblems/Databases/Department_Highest_Salary.sql) | Medium | https://leetcode.com/problems/department-highest-salary | +| [Exchange Seats](/LeetcodeProblems/Databases/Exchange_Seats.sql) | Medium | https://leetcode.com/problems/exchange-seats | +| [Nth Highest Salary](/LeetcodeProblems/Databases/nth_Highest_Salary.sql) | Medium | https://leetcode.com/problems/nth-highest-salary | +| [Combine Two Tables](/LeetcodeProblems/Databases/Combine_Two_Tables.sql) | Easy | https://leetcode.com/problems/combine-two-tables | +| [Second Highest Salary](/LeetcodeProblems/Databases/Second_highest_salary.sql)| Easy | https://leetcode.com/problems/second-highest-salary | +| [Customers Who Never Order](/LeetcodeProblems/Databases/Customers_Who_Never_Order.sql)| Easy | https://leetcode.com/problems/customers-who-never-order | +| [Reformat Department Table](/LeetcodeProblems/Databases/Reformat_Department_Table.sql) | Easy | https://leetcode.com/problems/reformat-department-table | +| [Employees Earning More Than Their Managers](/LeetcodeProblems/Databases/Employees_Earning_More_Than_Their_Managers.sql) | Easy | https://leetcode.com/problems/employees-earning-more-than-their-managers/ | +| [Delete Duplicate Emails](LeetcodeProblems/Databases/Delete_Duplicate_Emails.sql) | Easy | https://leetcode.com/problems/delete-duplicate-emails | +| [Rising Temperature](LeetcodeProblems/Databases/Rising_Temperature.sql) | 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: https://github.com/ignacio-chiazzo/Algorithms-Leetcode-Javascript/pull/39 diff --git a/readme.md b/readme.md index f2e8f80..aa333f4 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,135 @@ - [Maximal Square ](/LeetcodeProblems/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ +# 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 ` (e.g. `node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js`). + +**Linter:** This repository uses [`es-lint`](https://eslint.org/docs/latest/user-guide/command-line-interface). 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`](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems) which will automatically fix some of the errors. + +### Leetcode Problems + +| Name | Level | Link | +| - | - | - | +| [Edit Distance ](/LeetcodeProblems/Algorithms/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | +| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | +| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | +| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | +| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | +| [NQueens ](/LeetcodeProblems/Algorithms/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | +| [merge k sorted lists ](/LeetcodeProblems/Algorithms/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | +| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | +| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | +| [3Sum Closest](/LeetcodeProblems/Algorithms/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | +| [3Sum ](/LeetcodeProblems/Algorithms/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | +| [NumberOfIslands ](/LeetcodeProblems/Algorithms/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | +| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | +| [Add Two Numbers ](/LeetcodeProblems/Algorithms/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | +| [Clone Graph ](/LeetcodeProblems/Algorithms/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | +| [Coin Change ](/LeetcodeProblems/Algorithms/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | +| [Container With Most Water](/LeetcodeProblems/Algorithms/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | +| [Design Circular Deque ](/LeetcodeProblems/Algorithms/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ +| [Escape The Ghosts](/LeetcodeProblems/Algorithms/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | +| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | +| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | +| [Group Anagrams ](/LeetcodeProblems/Algorithms/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ +| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | +| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | +| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/| +| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters| +| [Max Area Of Island ](/LeetcodeProblems/Algorithms/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | +| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | +| [Maximal Square ](/LeetcodeProblems/Algorithms/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | +| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | +| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | +| [Permutations ](/LeetcodeProblems/Algorithms/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Permutations II ](/LeetcodeProblems/Algorithms/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | +| [Permutation in String](/LeetcodeProblems/Algorithms/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | +| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | +| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | +| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Simplify Path ](/LeetcodeProblems/Algorithms/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | +| [Spiral Matrix ](/LeetcodeProblems/Algorithms/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | +| [Subsets ](/LeetcodeProblems/Algorithms/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | +| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | +| [Unique Paths ](/LeetcodeProblems/Algorithms/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | +| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/Verify_Preorder_Serialization_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ | +| [Construct Binary Tree from Preorder and Inorder Traversal ](/LeetcodeProblems/Algorithms/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js) | Medium | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ | +| [Lowest Common Ancestor of a Binary Tree ](/LeetcodeProblems/Algorithms/Lowest_Common_Ancestor_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ | +| [Maximum Sum of an Hourglass](/LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | +| [Next Permutation](/LeetcodeProblems/Algorithms/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | +| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/Time_Needed_Rearrange_Binary_String.js)| Medium | https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/ | +| [Find Subarrays With Equal Sum ](/LeetcodeProblems/Algorithms/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | +| [Reverse Integer](/LeetcodeProblems/Algorithms/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | +| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | +| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | +| [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ +| [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | +| [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | +| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | +| [Maximun Subarray ](/LeetcodeProblems/Algorithms/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | +| [Min Stack ](/LeetcodeProblems/Algorithms/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | +| [Reverse String II ](/LeetcodeProblems/Algorithms/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | +| [Same Tree ](/LeetcodeProblems/Algorithms/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | +| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | +| [Symmetric Tree ](/LeetcodeProblems/Algorithms/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | +| [Valid Parentheses ](/LeetcodeProblems/Algorithms/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | +| [Backspace String Compare ](/LeetcodeProblems/Algorithms/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | +| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | +| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | +| [Majority Element](/LeetcodeProblems/Algorithms/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | +| [Longest Common Prefix](/LeetcodeProblems/Algorithms/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | +| [Two Sum](/LeetcodeProblems/Algorithms/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | +| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/Tic_Tac_Toe.js) | | | +| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/Permutations_With_Duplicates.js) | | | +| [Deletion Distance](/LeetcodeProblems/Algorithms/Deletion_Distance.js) | | | +| [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | +| [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | +| [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | + +### Sorting Algorithms +| Algoritmhs | +| - | +| [Heap Sort](/SortingAlgorithms/heapSort.js) | +| [Quick Sort](/SortingAlgorithms/QuickSort.js) | + +### Databases +| Problems | Level | Link | +|-|-|-| +| [Trips and Users](/LeetcodeProblems/Databases/Trips_and_Users.sql) | Hard | https://leetcode.com/problems/trips-and-users/ | +| [Human Traffic of Stadium](/LeetcodeProblems/Databases/Human_Traffic_of_Stadium.sql) | Hard | https://leetcode.com/problems/human-traffic-of-stadium | +| [Rank Scores](/LeetcodeProblems/Databases/Rank_Scores.sql) | Medium | https://leetcode.com/problems/rank-scores | +| [Consecutive Numbers](/LeetcodeProblems/Databases/Consecutive_Numbers.sql) | Medium | https://leetcode.com/problems/consecutive-numbers | +| [Department Highest Salary](/LeetcodeProblems/Databases/Department_Highest_Salary.sql) | Medium | https://leetcode.com/problems/department-highest-salary | +| [Exchange Seats](/LeetcodeProblems/Databases/Exchange_Seats.sql) | Medium | https://leetcode.com/problems/exchange-seats | +| [Nth Highest Salary](/LeetcodeProblems/Databases/nth_Highest_Salary.sql) | Medium | https://leetcode.com/problems/nth-highest-salary | +| [Combine Two Tables](/LeetcodeProblems/Databases/Combine_Two_Tables.sql) | Easy | https://leetcode.com/problems/combine-two-tables | +| [Second Highest Salary](/LeetcodeProblems/Databases/Second_highest_salary.sql)| Easy | https://leetcode.com/problems/second-highest-salary | +| [Customers Who Never Order](/LeetcodeProblems/Databases/Customers_Who_Never_Order.sql)| Easy | https://leetcode.com/problems/customers-who-never-order | +| [Reformat Department Table](/LeetcodeProblems/Databases/Reformat_Department_Table.sql) | Easy | https://leetcode.com/problems/reformat-department-table | +| [Employees Earning More Than Their Managers](/LeetcodeProblems/Databases/Employees_Earning_More_Than_Their_Managers.sql) | Easy | https://leetcode.com/problems/employees-earning-more-than-their-managers/ | +| [Delete Duplicate Emails](LeetcodeProblems/Databases/Delete_Duplicate_Emails.sql) | Easy | https://leetcode.com/problems/delete-duplicate-emails | +| [Rising Temperature](LeetcodeProblems/Databases/Rising_Temperature.sql) | 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: https://github.com/ignacio-chiazzo/Algorithms-Leetcode-Javascript/pull/39 From f3986e1be74a7ceb9b1513930b9b8c5ba05a420d Mon Sep 17 00:00:00 2001 From: Chaitra Bhat Date: 2022年10月23日 20:42:35 +0530 Subject: [PATCH 7/9] updated readme --- README.md | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa333f4..0b2e13d 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil | [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | | [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | | [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ | [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | | [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | | [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | diff --git a/readme.md b/readme.md index aa333f4..0b2e13d 100644 --- a/readme.md +++ b/readme.md @@ -70,7 +70,7 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil | [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | | [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | | [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ | [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | | [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | | [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | From b518c4578fa3eea5427cc56078d766b974ad1155 Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 20:49:47 +0530 Subject: [PATCH 8/9] Revert "Revert "readme.md created"" This reverts commit 47220c65a502c125944dfdca09a79dc3bb9b9db5. --- readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f2e8f80 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ + [Maximal Square ](/LeetcodeProblems/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ From c76622dbf34b43238502d3a973ec5656095fd3ef Mon Sep 17 00:00:00 2001 From: Chaitra Bhat <79207846+chaitra-bhat383@users.noreply.github.com> Date: 2022年10月23日 20:52:28 +0530 Subject: [PATCH 9/9] updated readme --- readme.md | 135 ------------------------------------------------------ 1 file changed, 135 deletions(-) delete mode 100644 readme.md diff --git a/readme.md b/readme.md deleted file mode 100644 index 0b2e13d..0000000 --- a/readme.md +++ /dev/null @@ -1,135 +0,0 @@ -# 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 ` (e.g. `node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js`). - -**Linter:** This repository uses [`es-lint`](https://eslint.org/docs/latest/user-guide/command-line-interface). 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`](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems) which will automatically fix some of the errors. - -### Leetcode Problems - -| Name | Level | Link | -| - | - | - | -| [Edit Distance ](/LeetcodeProblems/Algorithms/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | -| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | -| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | -| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | -| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | -| [NQueens ](/LeetcodeProblems/Algorithms/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | -| [merge k sorted lists ](/LeetcodeProblems/Algorithms/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | -| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | -| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | -| [3Sum Closest](/LeetcodeProblems/Algorithms/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | -| [3Sum ](/LeetcodeProblems/Algorithms/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | -| [NumberOfIslands ](/LeetcodeProblems/Algorithms/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | -| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | -| [Add Two Numbers ](/LeetcodeProblems/Algorithms/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | -| [Clone Graph ](/LeetcodeProblems/Algorithms/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | -| [Coin Change ](/LeetcodeProblems/Algorithms/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | -| [Container With Most Water](/LeetcodeProblems/Algorithms/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | -| [Design Circular Deque ](/LeetcodeProblems/Algorithms/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ -| [Escape The Ghosts](/LeetcodeProblems/Algorithms/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | -| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | -| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | -| [Group Anagrams ](/LeetcodeProblems/Algorithms/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ -| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | -| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | -| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/| -| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters| -| [Max Area Of Island ](/LeetcodeProblems/Algorithms/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | -| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | -| [Maximal Square ](/LeetcodeProblems/Algorithms/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | -| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | -| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | -| [Permutations ](/LeetcodeProblems/Algorithms/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Permutations II ](/LeetcodeProblems/Algorithms/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | -| [Permutation in String](/LeetcodeProblems/Algorithms/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | -| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | -| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | -| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Simplify Path ](/LeetcodeProblems/Algorithms/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | -| [Spiral Matrix ](/LeetcodeProblems/Algorithms/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | -| [Subsets ](/LeetcodeProblems/Algorithms/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | -| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | -| [Unique Paths ](/LeetcodeProblems/Algorithms/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | -| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/Verify_Preorder_Serialization_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ | -| [Construct Binary Tree from Preorder and Inorder Traversal ](/LeetcodeProblems/Algorithms/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js) | Medium | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ | -| [Lowest Common Ancestor of a Binary Tree ](/LeetcodeProblems/Algorithms/Lowest_Common_Ancestor_of_a_Binary_Tree.js) | Medium | https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ | -| [Maximum Sum of an Hourglass](/LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | -| [Next Permutation](/LeetcodeProblems/Algorithms/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | -| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/Time_Needed_Rearrange_Binary_String.js)| Medium | https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/ | -| [Find Subarrays With Equal Sum ](/LeetcodeProblems/Algorithms/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | -| [Reverse Integer](/LeetcodeProblems/Algorithms/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | -| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | -| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | -| [Gas Station](/LeetcodeProblems/Algorithms/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ -| [Flood Fill ](/LeetcodeProblems/Algorithms/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | -| [Implement stack using queues ](/LeetcodeProblems/Algorithms/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | -| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | -| [Maximun Subarray ](/LeetcodeProblems/Algorithms/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | -| [Min Stack ](/LeetcodeProblems/Algorithms/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | -| [Reverse String II ](/LeetcodeProblems/Algorithms/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | -| [Same Tree ](/LeetcodeProblems/Algorithms/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | -| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | -| [Symmetric Tree ](/LeetcodeProblems/Algorithms/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | -| [Valid Parentheses ](/LeetcodeProblems/Algorithms/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | -| [Backspace String Compare ](/LeetcodeProblems/Algorithms/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | -| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | -| [Binary Gap ](/LeetcodeProblems/Algorithms/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | -| [Majority Element](/LeetcodeProblems/Algorithms/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | -| [Longest Common Prefix](/LeetcodeProblems/Algorithms/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | -| [Two Sum](/LeetcodeProblems/Algorithms/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | -| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/Tic_Tac_Toe.js) | | | -| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/Permutations_With_Duplicates.js) | | | -| [Deletion Distance](/LeetcodeProblems/Algorithms/Deletion_Distance.js) | | | -| [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | | -| [Happy Number](https://leetcode.com/problems/happy-number/) | Easy | https://leetcode.com/problems/happy-number/ | -| [Shuffle String](https://leetcode.com/problems/shuffle-string/) | Easy | https://leetcode.com/problems/shuffle-string/ | - -### Sorting Algorithms -| Algoritmhs | -| - | -| [Heap Sort](/SortingAlgorithms/heapSort.js) | -| [Quick Sort](/SortingAlgorithms/QuickSort.js) | - -### Databases -| Problems | Level | Link | -|-|-|-| -| [Trips and Users](/LeetcodeProblems/Databases/Trips_and_Users.sql) | Hard | https://leetcode.com/problems/trips-and-users/ | -| [Human Traffic of Stadium](/LeetcodeProblems/Databases/Human_Traffic_of_Stadium.sql) | Hard | https://leetcode.com/problems/human-traffic-of-stadium | -| [Rank Scores](/LeetcodeProblems/Databases/Rank_Scores.sql) | Medium | https://leetcode.com/problems/rank-scores | -| [Consecutive Numbers](/LeetcodeProblems/Databases/Consecutive_Numbers.sql) | Medium | https://leetcode.com/problems/consecutive-numbers | -| [Department Highest Salary](/LeetcodeProblems/Databases/Department_Highest_Salary.sql) | Medium | https://leetcode.com/problems/department-highest-salary | -| [Exchange Seats](/LeetcodeProblems/Databases/Exchange_Seats.sql) | Medium | https://leetcode.com/problems/exchange-seats | -| [Nth Highest Salary](/LeetcodeProblems/Databases/nth_Highest_Salary.sql) | Medium | https://leetcode.com/problems/nth-highest-salary | -| [Combine Two Tables](/LeetcodeProblems/Databases/Combine_Two_Tables.sql) | Easy | https://leetcode.com/problems/combine-two-tables | -| [Second Highest Salary](/LeetcodeProblems/Databases/Second_highest_salary.sql)| Easy | https://leetcode.com/problems/second-highest-salary | -| [Customers Who Never Order](/LeetcodeProblems/Databases/Customers_Who_Never_Order.sql)| Easy | https://leetcode.com/problems/customers-who-never-order | -| [Reformat Department Table](/LeetcodeProblems/Databases/Reformat_Department_Table.sql) | Easy | https://leetcode.com/problems/reformat-department-table | -| [Employees Earning More Than Their Managers](/LeetcodeProblems/Databases/Employees_Earning_More_Than_Their_Managers.sql) | Easy | https://leetcode.com/problems/employees-earning-more-than-their-managers/ | -| [Delete Duplicate Emails](LeetcodeProblems/Databases/Delete_Duplicate_Emails.sql) | Easy | https://leetcode.com/problems/delete-duplicate-emails | -| [Rising Temperature](LeetcodeProblems/Databases/Rising_Temperature.sql) | 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: https://github.com/ignacio-chiazzo/Algorithms-Leetcode-Javascript/pull/39

AltStyle によって変換されたページ (->オリジナル) /