diff --git a/LeetcodeProblems/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js b/LeetcodeProblems/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js new file mode 100644 index 0000000..524f63f --- /dev/null +++ b/LeetcodeProblems/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js @@ -0,0 +1,80 @@ +/* +3226. Number of Bit Changes to Make Two Integers Equal +https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal/description/ + +You are given two positive integers n and k. + +You can choose any bit in the binary representation of n that is equal to 1 and change it to 0. + +Return the number of changes needed to make n equal to k. If it is impossible, return -1. + +Example 1: + +Input: n = 13, k = 4 + +Output: 2 + +Explanation: +Initially, the binary representations of n and k are n = (1101)base2 and k = (0100)base2. +We can change the first and fourth bits of n. The resulting integer is n = (0100)base2 = k. + + +Example 2: + +Input: n = 21, k = 21 + +Output: 0 + +Explanation: +n and k are already equal, so no changes are needed. + +Example 3: + +Input: n = 14, k = 13 + +Output: -1 + +Explanation: +It is not possible to make n equal to k. + +Constraints: + +1 <= n, k <= 10^6 + +*/ + +/* +Approach +Check if transformation is possible: + +Use a bitwise AND operation to ensure all 1 bits in k are also 1 bits in n. If not, return -1. +Calculate the number of changes: + +Use a bitwise XOR operation to identify differing bits between n and k. +Count the number of 1s in the result of the XOR operation. +*/ + +/** + * @param {number} n + * @param {number} k + * @return {number} + */ +var minChanges = function bitChanges(n, k) { + // Check if transformation is possible + if ((n & k) !== k) { + return -1; + } + + // Calculate the number of changes + let changes = 0; + let diff = n ^ k; + + while (diff > 0) { + changes += diff & 1; + diff >>= 1; + } + + return changes; +}; + +module.exports.minChanges = minChanges; diff --git a/LeetcodeProblemsTests/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js b/LeetcodeProblemsTests/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js new file mode 100644 index 0000000..9af014e --- /dev/null +++ b/LeetcodeProblemsTests/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js @@ -0,0 +1,20 @@ +const assert = require("assert"); +const bitReverseToMakeNumberEqual = require("../../../LeetcodeProblems/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal").bitChanges; + + +function test() { + assert.deepEqual( + bitChanges(13, 4), + 2 + ); + assert.deepEqual( + bitChanges(21, 21), + 0 + ); + assert.deepEqual( + bitChanges(14, 13), + -1 +); +} + +module.exports.test = test; diff --git a/README.md b/README.md index 4356066..bfbd70a 100644 --- a/README.md +++ b/README.md @@ -13,86 +13,87 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil ### Leetcode Problems -| Name | Level | Link | -| - | - | - | -| [Edit Distance ](/LeetcodeProblems/Algorithms/hard/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | -| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/hard/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | -| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/hard/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | -| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/hard/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | -| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/hard/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | -| [NQueens ](/LeetcodeProblems/Algorithms/hard/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | -| [merge k sorted lists ](/LeetcodeProblems/Algorithms/hard/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | -| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/hard/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | -| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/medium/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | -| [3Sum Closest](/LeetcodeProblems/Algorithms/medium/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | -| [3Sum ](/LeetcodeProblems/Algorithms/medium/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | -| [NumberOfIslands ](/LeetcodeProblems/Algorithms/medium/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | -| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/medium/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | -| [Add Two Numbers ](/LeetcodeProblems/Algorithms/medium/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | -| [Clone Graph ](/LeetcodeProblems/Algorithms/medium/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | -| [Coin Change ](/LeetcodeProblems/Algorithms/medium/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | -| [Container With Most Water](/LeetcodeProblems/Algorithms/medium/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | -| [Design Circular Deque ](/LeetcodeProblems/Algorithms/medium/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ -| [Escape The Ghosts](/LeetcodeProblems/Algorithms/medium/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | -| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/medium/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | -| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/medium/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | -| [Group Anagrams ](/LeetcodeProblems/Algorithms/medium/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ -| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/medium/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | -| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/medium/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | -| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/medium/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/| -| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/medium/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters| -| [Max Area Of Island ](/LeetcodeProblems/Algorithms/medium/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | -| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/medium/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | -| [Maximal Square ](/LeetcodeProblems/Algorithms/medium/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | -| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/medium/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | -| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/medium/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | -| [Permutations ](/LeetcodeProblems/Algorithms/medium/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Permutations II ](/LeetcodeProblems/Algorithms/medium/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | -| [Permutation in String](/LeetcodeProblems/Algorithms/medium/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | -| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/medium/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | -| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/medium/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | -| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/medium/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | -| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/medium/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/medium/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | -| [Simplify Path ](/LeetcodeProblems/Algorithms/medium/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | -| [Spiral Matrix ](/LeetcodeProblems/Algorithms/medium/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | -| [Subsets ](/LeetcodeProblems/Algorithms/medium/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | -| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/medium/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | -| [Unique Paths ](/LeetcodeProblems/Algorithms/medium/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | -| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/medium/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/medium/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/medium/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/medium/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | -| [Next Permutation](/LeetcodeProblems/Algorithms/medium/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | -| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/medium/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/medium/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | -| [Reverse Integer](/LeetcodeProblems/Algorithms/medium/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | -| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/medium/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | -| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/medium/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | -| [Gas Station](/LeetcodeProblems/Algorithms/medium/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/| -| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/medium/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ -| [BestTimeToBuy](LeetcodeProblems/Algorithms/easy/Best_Time_To_Buy_And_Sell_Stock_II.js) | Medium | https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii | -| [Flood Fill ](/LeetcodeProblems/Algorithms/easy/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | -| [Implement stack using queues ](/LeetcodeProblems/Algorithms/easy/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | -| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/easy/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | -| [Maximun Subarray ](/LeetcodeProblems/Algorithms/easy/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | -| [Min Stack ](/LeetcodeProblems/Algorithms/easy/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | -| [Reverse String II ](/LeetcodeProblems/Algorithms/easy/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | -| [Same Tree ](/LeetcodeProblems/Algorithms/easy/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | -| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/easy/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | -| [Symmetric Tree ](/LeetcodeProblems/Algorithms/easy/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | -| [Valid Parentheses ](/LeetcodeProblems/Algorithms/easy/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | -| [Backspace String Compare ](/LeetcodeProblems/Algorithms/easy/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | -| [Binary Gap ](/LeetcodeProblems/Algorithms/easy/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | -| [Majority Element](/LeetcodeProblems/Algorithms/easy/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | -| [Longest Common Prefix](/LeetcodeProblems/Algorithms/easy/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | -| [Two Sum](/LeetcodeProblems/Algorithms/easy/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | -| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/easy/Tic_Tac_Toe.js) | Easy | | -| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/easy/Permutations_With_Duplicates.js) | Easy | | -| [Deletion Distance](/LeetcodeProblems/Algorithms/easy/Deletion_Distance.js) | Easy | | -| [Award Budget Cuts](/LeetcodeProblems/Algorithms/easy/Award_Budget_Cuts.js) | Easy | | -| [Happy Number](/LeetcodeProblems/Algorithms/easy/Happy_Number.js) | Easy | https://leetcode.com/problems/happy-number/ | -| [Shuffle String](/LeetcodeProblems/Algorithms/easy/Shuffle_String.js) | Easy | https://leetcode.com/problems/shuffle-string/ | +| Name | Level | Link | +|----------------------------------------------------------------------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------| +| [Edit Distance ](/LeetcodeProblems/Algorithms/hard/Edit_Distance.js) | Hard | https://leetcode.com/problems/edit-distance/ | +| [Remove Invalid Parentheses ](/LeetcodeProblems/Algorithms/hard/Remove_Invalid_Parentheses.js) | Hard | https://leetcode.com/problems/remove-invalid-parentheses/ | +| [Longest Consecutive Sequence ](/LeetcodeProblems/Algorithms/hard/Longest_Consecutive_Sequence.js) | Hard | https://leetcode.com/problems/longest-consecutive-sequence/ | +| [Minimum Window Substring ](/LeetcodeProblems/Algorithms/hard/Minimum_Window_Substring.js) | Hard | https://leetcode.com/problems/minimum-window-substring/ | +| [Regular Expression Matching ](/LeetcodeProblems/Algorithms/hard/Regular_Expression_Matching.js) | Hard | https://leetcode.com/problems/regular-expression-matching/ | +| [NQueens ](/LeetcodeProblems/Algorithms/hard/NQueens.js) | Hard | https://leetcode.com/problems/n-queens/ | +| [merge k sorted lists ](/LeetcodeProblems/Algorithms/hard/merge_k_sorted_lists.js) | Hard | https://leetcode.com/problems/merge-k-sorted-lists/ | +| [Set Matrix Zeroes](/LeetcodeProblems/Algorithms/hard/Set_Matrix_Zeroes.js) | Hard | https://leetcode.com/problems/set-matrix-zeroes/ | +| [Subarray Sum Equals K ](/LeetcodeProblems/Algorithms/medium/Subarray_Sum_Equals_K.js) | Medium | https://leetcode.com/problems/subarray-sum-equals-k/ | +| [3Sum Closest](/LeetcodeProblems/Algorithms/medium/3SumClosest.js) | Medium | https://leetcode.com/problems/3sum-closest/ | +| [3Sum ](/LeetcodeProblems/Algorithms/medium/3Sum.js) | Medium | https://leetcode.com/problems/3sum/ | +| [NumberOfIslands ](/LeetcodeProblems/Algorithms/medium/Number_of_Islands.js) | Medium | https://leetcode.com/problems/number-of-islands/ | +| [Swap Nodes in Pairs](/LeetcodeProblems/Algorithms/medium/Swap_Nodes_in_Pairs.js) | Medium | https://leetcode.com/problems/swap-nodes-in-pairs/ | +| [Add Two Numbers ](/LeetcodeProblems/Algorithms/medium/Add_Two_Numbers.js) | Medium | https://leetcode.com/problems/add-two-numbers/ | +| [Clone Graph ](/LeetcodeProblems/Algorithms/medium/Clone_Graph.js) | Medium | https://leetcode.com/problems/clone-graph/ | +| [Coin Change ](/LeetcodeProblems/Algorithms/medium/Coin_Change.js) | Medium | https://leetcode.com/problems/coin-change/ | +| [Container With Most Water](/LeetcodeProblems/Algorithms/medium/Container_With_Most_Water.js) | Medium | https://leetcode.com/problems/container-with-most-water/ | +| [Design Circular Deque ](/LeetcodeProblems/Algorithms/medium/Design_Circular_Deque.js) | Medium | https://leetcode.com/problems/design-circular-deque/ +| [Escape The Ghosts](/LeetcodeProblems/Algorithms/medium/Escape_The_Ghosts.js) | Medium | https://leetcode.com/problems/escape-the-ghosts/ | +| [Find All Anagrams in a String](/LeetcodeProblems/Algorithms/medium/Find_Anagrams.js) | Medium | https://leetcode.com/problems/find-all-anagrams-in-a-string/ | +| [Generate Parenthesis ](/LeetcodeProblems/Algorithms/medium/Generate_Parenthesis.js) | Medium | https://leetcode.com/problems/generate-parentheses | +| [Group Anagrams ](/LeetcodeProblems/Algorithms/medium/Group_Anagrams.js) | Medium | https://leetcode.com/problems/group-anagrams/ +| [Kth Largest Element in an Array ](/LeetcodeProblems/Algorithms/medium/Kth_Largest_Element_in_an_Array.js) | Medium | https://leetcode.com/problems/kth-largest-element-in-an-array/ | +| [Linked List Cycle II ](/LeetcodeProblems/Algorithms/medium/Linked_List_Cycle_II.js) | Medium | https://leetcode.com/problems/linked-list-cycle-ii/ | +| [Longest Palindromic Substring ](/LeetcodeProblems/Algorithms/medium/Longest_Palindromic_Substring.js) | Medium | https://leetcode.com/problems/longest-palindromic-substring/ | +| [Longest Substring Without Reapeating Characters](/LeetcodeProblems/Algorithms/medium/Longest_Substring.js) | Medium | https://leetcode.com/problems/longest-substring-without-repeating-characters | +| [Max Area Of Island ](/LeetcodeProblems/Algorithms/medium/Max_Area_Of_Island.js) | Medium | https://leetcode.com/problems/max-area-of-island/ | +| [Max Consecutive Ones III ](/LeetcodeProblems/Algorithms/medium/Max_Consecutive_Ones_III.js) | Medium | https://leetcode.com/problems/max-consecutive-ones-iii | +| [Maximal Square ](/LeetcodeProblems/Algorithms/medium/Maximal_Square.js) | Medium | https://leetcode.com/problems/maximal-square/ | +| [Minimum Add to Make Parentheses Valid ](/LeetcodeProblems/Algorithms/medium/Minimum_Add_To_Make_Parentheses_Valid.js) | Medium | https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ | +| [Minimum Size Subarray](/LeetcodeProblems/Algorithms/medium/Minimum_Size_Subarray.js) | Medium | https://leetcode.com/problems/minimum-size-subarray-sum | +| [Permutations ](/LeetcodeProblems/Algorithms/medium/Permutations.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Permutations II ](/LeetcodeProblems/Algorithms/medium/Permutations_II.js) | Medium | https://leetcode.com/problems/permutations-ii/ | +| [Permutation in String](/LeetcodeProblems/Algorithms/medium/Permutations_In_String.js) | Medium | https://leetcode.com/problems/permutation-in-string/ | +| [Permutations Without Duplicates ](/LeetcodeProblems/Algorithms/medium/Permutations_Without_Duplicates.js) | Medium | https://leetcode.com/problems/permutations/ | +| [Restore IP Addresses ](/LeetcodeProblems/Algorithms/medium/Restore_IP_Addresses.js) | Medium | https://leetcode.com/problems/restore-ip-addresses/ | +| [SearchIng Rotated Sorted Array ](/LeetcodeProblems/Algorithms/medium/SearchIng_Rotated_Sorted_Array.js) | Medium | https://leetcode.com/problems/search-in-rotated-sorted-array/ | +| [Search a 2D Matrix ](/LeetcodeProblems/Algorithms/medium/Search_a_2D_Matrix.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Search a 2D Matrix II ](/LeetcodeProblems/Algorithms/medium/Search_a_2D_Matrix_II.js) | Medium | https://leetcode.com/problems/search-a-2d-matrix/ | +| [Simplify Path ](/LeetcodeProblems/Algorithms/medium/Simplify_Path.js) | Medium | https://leetcode.com/problems/simplify-path/ | +| [Spiral Matrix ](/LeetcodeProblems/Algorithms/medium/Spiral_Matrix.js) | Medium | https://leetcode.com/problems/spiral-matrix/ | +| [Subsets ](/LeetcodeProblems/Algorithms/medium/Subsets.js) | Medium | https://leetcode.com/problems/subsets/ | +| [Unique Binary Search Trees ](/LeetcodeProblems/Algorithms/medium/Unique_Binary_Search_Trees.js) | Medium | https://leetcode.com/problems/unique-binary-search-trees/ | +| [Unique Paths ](/LeetcodeProblems/Algorithms/medium/Unique_Paths.js) | Medium | https://leetcode.com/problems/unique-paths/ | +| [Verify Preorder Serialization of a Binary Tree ](/LeetcodeProblems/Algorithms/medium/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/medium/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/medium/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/medium/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ | +| [Next Permutation](/LeetcodeProblems/Algorithms/medium/Next_Permutation.js) | Medium | https://leetcode.com/problems/next-permutation/ | +| [Time Needed to Rearrange a Binary String](/LeetcodeProblems/Algorithms/medium/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/medium/Find_Subarrays_With_Equal_Sums.js) | Medium | https://leetcode.com/problems/find-subarrays-with-equal-sum/ | +| [Reverse Integer](/LeetcodeProblems/Algorithms/medium/Reverse_Integer.js) | Medium | https://leetcode.com/problems/reverse-integer/ | +| [Minimize Maximum Pair Sum in Array ](/LeetcodeProblems/Algorithms/medium/Minimize_Maximum_Pair_Sum_In_Array.js) | Medium | https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ | +| [Top K Frequent Elements ](/LeetcodeProblems/Algorithms/medium/Top_K_Frequent_Elements.js) | Medium | https://leetcode.com/problems/top-k-frequent-elements/ | +| [Gas Station](/LeetcodeProblems/Algorithms/medium/GasStation/index.js) | Medium | https://leetcode.com/problems/gas-station/description/ | +| [K Closest Points to Origin](/LeetcodeProblems/Algorithms/medium/K_Closest_Points_to_Origin.js/) | Medium | https://leetcode.com/problems/k-closest-points-to-origin/ +| [BestTimeToBuy](LeetcodeProblems/Algorithms/easy/Best_Time_To_Buy_And_Sell_Stock_II.js) | Medium | https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii | +| [Flood Fill ](/LeetcodeProblems/Algorithms/easy/Flood_Fill.js) | Easy | https://leetcode.com/problems/flood-fill/ | +| [Implement stack using queues ](/LeetcodeProblems/Algorithms/easy/Implement_stack_using_queues.js) | Easy | https://leetcode.com/problems/implement-stack-using-queues/ | +| [Number of Segments in a String ](/LeetcodeProblems/Algorithms/easy/Number_of_Segments_in_a_String.js) | Easy | https://leetcode.com/problems/number-of-segments-in-a-string/ | +| [Maximun Subarray ](/LeetcodeProblems/Algorithms/easy/Maximun_Subarray.js) | Easy | https://leetcode.com/problems/maximum-subarray | +| [Min Stack ](/LeetcodeProblems/Algorithms/easy/Min_Stack.js) | Easy | https://leetcode.com/problems/min-stack/ | +| [Reverse String II ](/LeetcodeProblems/Algorithms/easy/Reverse_String_II.js) | Easy | https://leetcode.com/problems/reverse-string-ii/ | +| [Same Tree ](/LeetcodeProblems/Algorithms/easy/Same_Tree.js) | Easy | https://leetcode.com/problems/same-tree/ | +| [Sum Of Square Numbers ](/LeetcodeProblems/Algorithms/easy/Sum_Of_Square_Numbers.js) | Easy | https://leetcode.com/problems/sum-of-square-numbers/ | +| [Symmetric Tree ](/LeetcodeProblems/Algorithms/easy/Symmetric_Tree.js) | Easy | https://leetcode.com/problems/symmetric-tree/ | +| [Valid Parentheses ](/LeetcodeProblems/Algorithms/easy/Valid_Parentheses.js) | Easy | https://leetcode.com/problems/valid-parentheses/ | +| [Backspace String Compare ](/LeetcodeProblems/Algorithms/easy/Backspace_String_Compare.js) | Easy | https://leetcode.com/problems/backspace-string-compare/ | +| [Binary Gap ](/LeetcodeProblems/Algorithms/easy/Binary_Gap.js) | Easy | https://leetcode.com/problems/binary-gap/ | +| [Majority Element](/LeetcodeProblems/Algorithms/easy/Majority_Element.js) | Easy | https://leetcode.com/problems/majority-element/ | +| [Longest Common Prefix](/LeetcodeProblems/Algorithms/easy/Longest_Common_Prefix.js) | Easy | https://leetcode.com/problems/longest-common-prefix/ | +| [Two Sum](/LeetcodeProblems/Algorithms/easy/2Sum.js) | Easy | https://leetcode.com/problems/two-sum/ | +| [Tic Tac Toe ](/LeetcodeProblems/Algorithms/easy/Tic_Tac_Toe.js) | Easy | | +| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/easy/Permutations_With_Duplicates.js) | Easy | | +| [Deletion Distance](/LeetcodeProblems/Algorithms/easy/Deletion_Distance.js) | Easy | | +| [Award Budget Cuts](/LeetcodeProblems/Algorithms/easy/Award_Budget_Cuts.js) | Easy | | +| [Happy Number](/LeetcodeProblems/Algorithms/easy/Happy_Number.js) | Easy | https://leetcode.com/problems/happy-number/ | +| [Shuffle String](/LeetcodeProblems/Algorithms/easy/Shuffle_String.js) | Easy | https://leetcode.com/problems/shuffle-string/ | +| [Reverse bit to make number equal](/LeetcodeProblems/Algorithms/easy/Bit_Reverse_To_Make_Numbers_Equal.js.js) | Easy | https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal/ | ### Sorting Algorithms | Algoritmhs |