From 35f2533b87ff4c1aa46ba24a2c96f15a6097fd0d Mon Sep 17 00:00:00 2001 From: Sanzay Dahal Date: Sun, 26 Mar 2023 15:48:43 +1100 Subject: [PATCH 1/2] move all the existing solutions to python folder --- {Easy => python/Easy}/binary-search.py | 0 {Easy => python/Easy}/branch-sums.py | 0 {Easy => python/Easy}/bubble-sort.py | 0 {Easy => python/Easy}/caesar-cipher-encryptor.py | 0 {Easy => python/Easy}/class-photos.py | 0 {Easy => python/Easy}/depth-first-search.py | 0 {Easy => python/Easy}/find-closest-value-in-BST.py | 0 {Easy => python/Easy}/find-three-largest-numbers.py | 0 {Easy => python/Easy}/first-non-repeating-character.py | 0 {Easy => python/Easy}/generate-document.py | 0 {Easy => python/Easy}/insertion-sort.py | 0 {Easy => python/Easy}/minimum-waiting-time.py | 0 {Easy => python/Easy}/node-depths.py | 0 {Easy => python/Easy}/non-constructible-change.py | 0 {Easy => python/Easy}/nth-fibonacci.py | 0 {Easy => python/Easy}/palindrome-check.py | 0 {Easy => python/Easy}/product-sum.py | 0 {Easy => python/Easy}/remove-duplicates-from-linked-list.py | 0 {Easy => python/Easy}/run-length-encoding.py | 0 {Easy => python/Easy}/selection-sort.py | 0 {Easy => python/Easy}/sorted-square-array.py | 0 {Easy => python/Easy}/tandem-bicycle.py | 0 {Easy => python/Easy}/tournament-winner.py | 0 {Easy => python/Easy}/twoNumberSum.py | 0 {Easy => python/Easy}/validate-subsequence.py | 0 {Hard => python/Hard}/ambiguous-measurements.py | 0 {Hard => python/Hard}/boggle-board.py | 0 {Hard => python/Hard}/continuous-median.py | 0 {Hard => python/Hard}/dijkstra-algorithm.py | 0 {Hard => python/Hard}/disk-stacking.py | 0 {Hard => python/Hard}/find-loop.py | 0 {Hard => python/Hard}/find-nodes-distance-k.py | 0 {Hard => python/Hard}/four-number-sum.py | 0 {Hard => python/Hard}/generate-div-tags.py | 0 {Hard => python/Hard}/glob-matching.py | 0 {Hard => python/Hard}/heap-sort.py | 0 {Hard => python/Hard}/index-equals-value.py | 0 {Hard => python/Hard}/interweaving-strings.py | 0 {Hard => python/Hard}/inverted-bisection.py | 0 {Hard => python/Hard}/knapsack-problem.py | 0 {Hard => python/Hard}/laptop-rentals.py | 0 {Hard => python/Hard}/largest-range.py | 0 {Hard => python/Hard}/largest-rectangle-under-skyline.py | 0 {Hard => python/Hard}/longest-common-subsequence.py | 0 {Hard => python/Hard}/longest-substring-without-duplication.py | 0 {Hard => python/Hard}/lowest-common-manager.py | 0 {Hard => python/Hard}/max-path-sum-binary-trees.py | 0 {Hard => python/Hard}/max-sum-increasing-subsequence.py | 0 {Hard => python/Hard}/maximize-expression.py | 0 {Hard => python/Hard}/maximum-sum-submatrix.py | 0 {Hard => python/Hard}/merge-linked-list.py | 0 {Hard => python/Hard}/min-number-of-jumps.py | 0 {Hard => python/Hard}/min-rewards.py | 0 {Hard => python/Hard}/multi-string-search.py | 0 {Hard => python/Hard}/numbers-pi.py | 0 {Hard => python/Hard}/pattern-matcher.py | 0 {Hard => python/Hard}/quick-sort.py | 0 {Hard => python/Hard}/quickselect.py | 0 {Hard => python/Hard}/radix-sort.py | 0 {Hard => python/Hard}/reverse-linked-list.py | 0 {Hard => python/Hard}/same-bsts.py | 0 {Hard => python/Hard}/search-for-range.py | 0 {Hard => python/Hard}/shift-linked-list.py | 0 {Hard => python/Hard}/shifted-binary-search.py | 0 {Hard => python/Hard}/shorten-path.py | 0 {Hard => python/Hard}/solve-sudoku.py | 0 {Hard => python/Hard}/sort-k-sorted-array.py | 0 {Hard => python/Hard}/special-strings.py | 0 {Hard => python/Hard}/subarray-sort.py | 0 {Hard => python/Hard}/topological-sort.py | 0 {Hard => python/Hard}/underscorify-substring.py | 0 {Hard => python/Hard}/validate-three-nodes.py | 0 {Hard => python/Hard}/water-area.py | 0 {Hard => python/Hard}/zigzag-traverse.py | 0 {Medium => python/Medium}/array-of-products.py | 0 {Medium => python/Medium}/balanced-brackets.py | 0 {Medium => python/Medium}/binary-tree-diameter.py | 0 {Medium => python/Medium}/breadth-first-search.py | 0 {Medium => python/Medium}/bst-construction.py | 0 {Medium => python/Medium}/bst-traversal.py | 0 {Medium => python/Medium}/cycle-in-graph.py | 0 {Medium => python/Medium}/degrees-of-separation.py | 0 {Medium => python/Medium}/find-kth-largest-value-in-bst.py | 0 {Medium => python/Medium}/find-successor.py | 0 {Medium => python/Medium}/first-duplicate-value.py | 0 {Medium => python/Medium}/group-anagrams.py | 0 {Medium => python/Medium}/height-balanced-binary-tree.py | 0 {Medium => python/Medium}/invert-binary-tree.py | 0 {Medium => python/Medium}/kadane-algorithm.py | 0 {Medium => python/Medium}/levenshtein-distance.py | 0 {Medium => python/Medium}/linked-list-construction.py | 0 {Medium => python/Medium}/longest-palindromic-substring.py | 0 {Medium => python/Medium}/longest-peak.py | 0 {Medium => python/Medium}/max-subset-sum-no-adjacent.py | 0 {Medium => python/Medium}/merge-overlapping-intervals.py | 0 {Medium => python/Medium}/min-heap-construction.py | 0 {Medium => python/Medium}/min-height-BST.py | 0 {Medium => python/Medium}/min-max-stack-construction.py | 0 {Medium => python/Medium}/min-number-of-coins-for-change.py | 0 {Medium => python/Medium}/minimum-characters-for-words.py | 0 {Medium => python/Medium}/minimum-passes-of-matrix.py | 0 {Medium => python/Medium}/monotonic-array.py | 0 {Medium => python/Medium}/move-element-to-end.py | 0 {Medium => python/Medium}/next-greater-element.py | 0 {Medium => python/Medium}/number-of-ways-to-traverse-graph.py | 0 {Medium => python/Medium}/permutations.py | 0 {Medium => python/Medium}/phone-number-mnemonics.py | 0 {Medium => python/Medium}/powerset.py | 0 {Medium => python/Medium}/reconstruct-bst.py | 0 {Medium => python/Medium}/remove-islands.py | 0 {Medium => python/Medium}/remove-kth-node-from-end.py | 0 {Medium => python/Medium}/reverse-words-in-string.py | 0 {Medium => python/Medium}/river-sizes.py | 0 {Medium => python/Medium}/search-in-sorted-matrix.py | 0 {Medium => python/Medium}/single-cycle-check.py | 0 {Medium => python/Medium}/smallest-difference.py | 0 {Medium => python/Medium}/sort-stack.py | 0 {Medium => python/Medium}/spiral-traverse.py | 0 {Medium => python/Medium}/staircase-traversal.py | 0 {Medium => python/Medium}/suffix-trie-construction.py | 0 {Medium => python/Medium}/sum-of-linked-lists.py | 0 {Medium => python/Medium}/sunset-views.py | 0 {Medium => python/Medium}/task-assignment.py | 0 {Medium => python/Medium}/three-number-sort.py | 0 {Medium => python/Medium}/three-number-sum.py | 0 {Medium => python/Medium}/valid-ip-addresses.py | 0 {Medium => python/Medium}/valid-starting-city.py | 0 {Medium => python/Medium}/validate-bst.py | 0 {Medium => python/Medium}/ways-to-make-change.py | 0 {Medium => python/Medium}/youngest-common-ancestor.py | 0 {Very Hard => python/Very Hard}/A-star-algorithm.py | 0 {Very Hard => python/Very Hard}/LRU-cache.py | 0 {Very Hard => python/Very Hard}/airport-connections.py | 0 {Very Hard => python/Very Hard}/all-kinds-of-node-depths.py | 0 {Very Hard => python/Very Hard}/apartment-hunting.py | 0 {Very Hard => python/Very Hard}/calendar-matching.py | 0 {Very Hard => python/Very Hard}/compare-leaf-traversal.py | 0 {Very Hard => python/Very Hard}/count-inversions.py | 0 {Very Hard => python/Very Hard}/detect-arbitrage.py | 0 {Very Hard => python/Very Hard}/flatten-binary-tree.py | 0 {Very Hard => python/Very Hard}/iterative-inorder-traversal.py | 0 {Very Hard => python/Very Hard}/knuth-morris-pratt-algorithm.py | 0 {Very Hard => python/Very Hard}/line-through-points.py | 0 {Very Hard => python/Very Hard}/linked-list-palindrome.py | 0 {Very Hard => python/Very Hard}/longest-balanced-substring.py | 0 {Very Hard => python/Very Hard}/longest-increasing-subsequence.py | 0 {Very Hard => python/Very Hard}/longest-string-chain.py | 0 .../Very Hard}/max-profits-with-k-transactions.py | 0 {Very Hard => python/Very Hard}/merge-sort.py | 0 {Very Hard => python/Very Hard}/merge-sorted-arrays.py | 0 {Very Hard => python/Very Hard}/minimum-area-rectangle.py | 0 {Very Hard => python/Very Hard}/node-swap.py | 0 {Very Hard => python/Very Hard}/non-attacking-queens.py | 0 .../Very Hard}/number-of-binary-tree-topologies.py | 0 .../Very Hard}/palindrome-partitioning-min-cuts.py | 0 {Very Hard => python/Very Hard}/rearrange-linked-list.py | 0 {Very Hard => python/Very Hard}/rectangle-mania.py | 0 {Very Hard => python/Very Hard}/right-sibling-tree.py | 0 {Very Hard => python/Very Hard}/right-smaller-than.py | 0 {Very Hard => python/Very Hard}/smallest-substring-containing.py | 0 {Very Hard => python/Very Hard}/square-of-zeroes.py | 0 {Very Hard => python/Very Hard}/two-edge-connected-graph.py | 0 {Very Hard => python/Very Hard}/waterfall-streams.py | 0 {Very Hard => python/Very Hard}/zip-linked-list.py | 0 164 files changed, 0 insertions(+), 0 deletions(-) rename {Easy => python/Easy}/binary-search.py (100%) rename {Easy => python/Easy}/branch-sums.py (100%) rename {Easy => python/Easy}/bubble-sort.py (100%) rename {Easy => python/Easy}/caesar-cipher-encryptor.py (100%) rename {Easy => python/Easy}/class-photos.py (100%) rename {Easy => python/Easy}/depth-first-search.py (100%) rename {Easy => python/Easy}/find-closest-value-in-BST.py (100%) rename {Easy => python/Easy}/find-three-largest-numbers.py (100%) rename {Easy => python/Easy}/first-non-repeating-character.py (100%) rename {Easy => python/Easy}/generate-document.py (100%) rename {Easy => python/Easy}/insertion-sort.py (100%) rename {Easy => python/Easy}/minimum-waiting-time.py (100%) rename {Easy => python/Easy}/node-depths.py (100%) rename {Easy => python/Easy}/non-constructible-change.py (100%) rename {Easy => python/Easy}/nth-fibonacci.py (100%) rename {Easy => python/Easy}/palindrome-check.py (100%) rename {Easy => python/Easy}/product-sum.py (100%) rename {Easy => python/Easy}/remove-duplicates-from-linked-list.py (100%) rename {Easy => python/Easy}/run-length-encoding.py (100%) rename {Easy => python/Easy}/selection-sort.py (100%) rename {Easy => python/Easy}/sorted-square-array.py (100%) rename {Easy => python/Easy}/tandem-bicycle.py (100%) rename {Easy => python/Easy}/tournament-winner.py (100%) rename {Easy => python/Easy}/twoNumberSum.py (100%) rename {Easy => python/Easy}/validate-subsequence.py (100%) rename {Hard => python/Hard}/ambiguous-measurements.py (100%) rename {Hard => python/Hard}/boggle-board.py (100%) rename {Hard => python/Hard}/continuous-median.py (100%) rename {Hard => python/Hard}/dijkstra-algorithm.py (100%) rename {Hard => python/Hard}/disk-stacking.py (100%) rename {Hard => python/Hard}/find-loop.py (100%) rename {Hard => python/Hard}/find-nodes-distance-k.py (100%) rename {Hard => python/Hard}/four-number-sum.py (100%) rename {Hard => python/Hard}/generate-div-tags.py (100%) rename {Hard => python/Hard}/glob-matching.py (100%) rename {Hard => python/Hard}/heap-sort.py (100%) rename {Hard => python/Hard}/index-equals-value.py (100%) rename {Hard => python/Hard}/interweaving-strings.py (100%) rename {Hard => python/Hard}/inverted-bisection.py (100%) rename {Hard => python/Hard}/knapsack-problem.py (100%) rename {Hard => python/Hard}/laptop-rentals.py (100%) rename {Hard => python/Hard}/largest-range.py (100%) rename {Hard => python/Hard}/largest-rectangle-under-skyline.py (100%) rename {Hard => python/Hard}/longest-common-subsequence.py (100%) rename {Hard => python/Hard}/longest-substring-without-duplication.py (100%) rename {Hard => python/Hard}/lowest-common-manager.py (100%) rename {Hard => python/Hard}/max-path-sum-binary-trees.py (100%) rename {Hard => python/Hard}/max-sum-increasing-subsequence.py (100%) rename {Hard => python/Hard}/maximize-expression.py (100%) rename {Hard => python/Hard}/maximum-sum-submatrix.py (100%) rename {Hard => python/Hard}/merge-linked-list.py (100%) rename {Hard => python/Hard}/min-number-of-jumps.py (100%) rename {Hard => python/Hard}/min-rewards.py (100%) rename {Hard => python/Hard}/multi-string-search.py (100%) rename {Hard => python/Hard}/numbers-pi.py (100%) rename {Hard => python/Hard}/pattern-matcher.py (100%) rename {Hard => python/Hard}/quick-sort.py (100%) rename {Hard => python/Hard}/quickselect.py (100%) rename {Hard => python/Hard}/radix-sort.py (100%) rename {Hard => python/Hard}/reverse-linked-list.py (100%) rename {Hard => python/Hard}/same-bsts.py (100%) rename {Hard => python/Hard}/search-for-range.py (100%) rename {Hard => python/Hard}/shift-linked-list.py (100%) rename {Hard => python/Hard}/shifted-binary-search.py (100%) rename {Hard => python/Hard}/shorten-path.py (100%) rename {Hard => python/Hard}/solve-sudoku.py (100%) rename {Hard => python/Hard}/sort-k-sorted-array.py (100%) rename {Hard => python/Hard}/special-strings.py (100%) rename {Hard => python/Hard}/subarray-sort.py (100%) rename {Hard => python/Hard}/topological-sort.py (100%) rename {Hard => python/Hard}/underscorify-substring.py (100%) rename {Hard => python/Hard}/validate-three-nodes.py (100%) rename {Hard => python/Hard}/water-area.py (100%) rename {Hard => python/Hard}/zigzag-traverse.py (100%) rename {Medium => python/Medium}/array-of-products.py (100%) rename {Medium => python/Medium}/balanced-brackets.py (100%) rename {Medium => python/Medium}/binary-tree-diameter.py (100%) rename {Medium => python/Medium}/breadth-first-search.py (100%) rename {Medium => python/Medium}/bst-construction.py (100%) rename {Medium => python/Medium}/bst-traversal.py (100%) rename {Medium => python/Medium}/cycle-in-graph.py (100%) rename {Medium => python/Medium}/degrees-of-separation.py (100%) rename {Medium => python/Medium}/find-kth-largest-value-in-bst.py (100%) rename {Medium => python/Medium}/find-successor.py (100%) rename {Medium => python/Medium}/first-duplicate-value.py (100%) rename {Medium => python/Medium}/group-anagrams.py (100%) rename {Medium => python/Medium}/height-balanced-binary-tree.py (100%) rename {Medium => python/Medium}/invert-binary-tree.py (100%) rename {Medium => python/Medium}/kadane-algorithm.py (100%) rename {Medium => python/Medium}/levenshtein-distance.py (100%) rename {Medium => python/Medium}/linked-list-construction.py (100%) rename {Medium => python/Medium}/longest-palindromic-substring.py (100%) rename {Medium => python/Medium}/longest-peak.py (100%) rename {Medium => python/Medium}/max-subset-sum-no-adjacent.py (100%) rename {Medium => python/Medium}/merge-overlapping-intervals.py (100%) rename {Medium => python/Medium}/min-heap-construction.py (100%) rename {Medium => python/Medium}/min-height-BST.py (100%) rename {Medium => python/Medium}/min-max-stack-construction.py (100%) rename {Medium => python/Medium}/min-number-of-coins-for-change.py (100%) rename {Medium => python/Medium}/minimum-characters-for-words.py (100%) rename {Medium => python/Medium}/minimum-passes-of-matrix.py (100%) rename {Medium => python/Medium}/monotonic-array.py (100%) rename {Medium => python/Medium}/move-element-to-end.py (100%) rename {Medium => python/Medium}/next-greater-element.py (100%) rename {Medium => python/Medium}/number-of-ways-to-traverse-graph.py (100%) rename {Medium => python/Medium}/permutations.py (100%) rename {Medium => python/Medium}/phone-number-mnemonics.py (100%) rename {Medium => python/Medium}/powerset.py (100%) rename {Medium => python/Medium}/reconstruct-bst.py (100%) rename {Medium => python/Medium}/remove-islands.py (100%) rename {Medium => python/Medium}/remove-kth-node-from-end.py (100%) rename {Medium => python/Medium}/reverse-words-in-string.py (100%) rename {Medium => python/Medium}/river-sizes.py (100%) rename {Medium => python/Medium}/search-in-sorted-matrix.py (100%) rename {Medium => python/Medium}/single-cycle-check.py (100%) rename {Medium => python/Medium}/smallest-difference.py (100%) rename {Medium => python/Medium}/sort-stack.py (100%) rename {Medium => python/Medium}/spiral-traverse.py (100%) rename {Medium => python/Medium}/staircase-traversal.py (100%) rename {Medium => python/Medium}/suffix-trie-construction.py (100%) rename {Medium => python/Medium}/sum-of-linked-lists.py (100%) rename {Medium => python/Medium}/sunset-views.py (100%) rename {Medium => python/Medium}/task-assignment.py (100%) rename {Medium => python/Medium}/three-number-sort.py (100%) rename {Medium => python/Medium}/three-number-sum.py (100%) rename {Medium => python/Medium}/valid-ip-addresses.py (100%) rename {Medium => python/Medium}/valid-starting-city.py (100%) rename {Medium => python/Medium}/validate-bst.py (100%) rename {Medium => python/Medium}/ways-to-make-change.py (100%) rename {Medium => python/Medium}/youngest-common-ancestor.py (100%) rename {Very Hard => python/Very Hard}/A-star-algorithm.py (100%) rename {Very Hard => python/Very Hard}/LRU-cache.py (100%) rename {Very Hard => python/Very Hard}/airport-connections.py (100%) rename {Very Hard => python/Very Hard}/all-kinds-of-node-depths.py (100%) rename {Very Hard => python/Very Hard}/apartment-hunting.py (100%) rename {Very Hard => python/Very Hard}/calendar-matching.py (100%) rename {Very Hard => python/Very Hard}/compare-leaf-traversal.py (100%) rename {Very Hard => python/Very Hard}/count-inversions.py (100%) rename {Very Hard => python/Very Hard}/detect-arbitrage.py (100%) rename {Very Hard => python/Very Hard}/flatten-binary-tree.py (100%) rename {Very Hard => python/Very Hard}/iterative-inorder-traversal.py (100%) rename {Very Hard => python/Very Hard}/knuth-morris-pratt-algorithm.py (100%) rename {Very Hard => python/Very Hard}/line-through-points.py (100%) rename {Very Hard => python/Very Hard}/linked-list-palindrome.py (100%) rename {Very Hard => python/Very Hard}/longest-balanced-substring.py (100%) rename {Very Hard => python/Very Hard}/longest-increasing-subsequence.py (100%) rename {Very Hard => python/Very Hard}/longest-string-chain.py (100%) rename {Very Hard => python/Very Hard}/max-profits-with-k-transactions.py (100%) rename {Very Hard => python/Very Hard}/merge-sort.py (100%) rename {Very Hard => python/Very Hard}/merge-sorted-arrays.py (100%) rename {Very Hard => python/Very Hard}/minimum-area-rectangle.py (100%) rename {Very Hard => python/Very Hard}/node-swap.py (100%) rename {Very Hard => python/Very Hard}/non-attacking-queens.py (100%) rename {Very Hard => python/Very Hard}/number-of-binary-tree-topologies.py (100%) rename {Very Hard => python/Very Hard}/palindrome-partitioning-min-cuts.py (100%) rename {Very Hard => python/Very Hard}/rearrange-linked-list.py (100%) rename {Very Hard => python/Very Hard}/rectangle-mania.py (100%) rename {Very Hard => python/Very Hard}/right-sibling-tree.py (100%) rename {Very Hard => python/Very Hard}/right-smaller-than.py (100%) rename {Very Hard => python/Very Hard}/smallest-substring-containing.py (100%) rename {Very Hard => python/Very Hard}/square-of-zeroes.py (100%) rename {Very Hard => python/Very Hard}/two-edge-connected-graph.py (100%) rename {Very Hard => python/Very Hard}/waterfall-streams.py (100%) rename {Very Hard => python/Very Hard}/zip-linked-list.py (100%) diff --git a/Easy/binary-search.py b/python/Easy/binary-search.py similarity index 100% rename from Easy/binary-search.py rename to python/Easy/binary-search.py diff --git a/Easy/branch-sums.py b/python/Easy/branch-sums.py similarity index 100% rename from Easy/branch-sums.py rename to python/Easy/branch-sums.py diff --git a/Easy/bubble-sort.py b/python/Easy/bubble-sort.py similarity index 100% rename from Easy/bubble-sort.py rename to python/Easy/bubble-sort.py diff --git a/Easy/caesar-cipher-encryptor.py b/python/Easy/caesar-cipher-encryptor.py similarity index 100% rename from Easy/caesar-cipher-encryptor.py rename to python/Easy/caesar-cipher-encryptor.py diff --git a/Easy/class-photos.py b/python/Easy/class-photos.py similarity index 100% rename from Easy/class-photos.py rename to python/Easy/class-photos.py diff --git a/Easy/depth-first-search.py b/python/Easy/depth-first-search.py similarity index 100% rename from Easy/depth-first-search.py rename to python/Easy/depth-first-search.py diff --git a/Easy/find-closest-value-in-BST.py b/python/Easy/find-closest-value-in-BST.py similarity index 100% rename from Easy/find-closest-value-in-BST.py rename to python/Easy/find-closest-value-in-BST.py diff --git a/Easy/find-three-largest-numbers.py b/python/Easy/find-three-largest-numbers.py similarity index 100% rename from Easy/find-three-largest-numbers.py rename to python/Easy/find-three-largest-numbers.py diff --git a/Easy/first-non-repeating-character.py b/python/Easy/first-non-repeating-character.py similarity index 100% rename from Easy/first-non-repeating-character.py rename to python/Easy/first-non-repeating-character.py diff --git a/Easy/generate-document.py b/python/Easy/generate-document.py similarity index 100% rename from Easy/generate-document.py rename to python/Easy/generate-document.py diff --git a/Easy/insertion-sort.py b/python/Easy/insertion-sort.py similarity index 100% rename from Easy/insertion-sort.py rename to python/Easy/insertion-sort.py diff --git a/Easy/minimum-waiting-time.py b/python/Easy/minimum-waiting-time.py similarity index 100% rename from Easy/minimum-waiting-time.py rename to python/Easy/minimum-waiting-time.py diff --git a/Easy/node-depths.py b/python/Easy/node-depths.py similarity index 100% rename from Easy/node-depths.py rename to python/Easy/node-depths.py diff --git a/Easy/non-constructible-change.py b/python/Easy/non-constructible-change.py similarity index 100% rename from Easy/non-constructible-change.py rename to python/Easy/non-constructible-change.py diff --git a/Easy/nth-fibonacci.py b/python/Easy/nth-fibonacci.py similarity index 100% rename from Easy/nth-fibonacci.py rename to python/Easy/nth-fibonacci.py diff --git a/Easy/palindrome-check.py b/python/Easy/palindrome-check.py similarity index 100% rename from Easy/palindrome-check.py rename to python/Easy/palindrome-check.py diff --git a/Easy/product-sum.py b/python/Easy/product-sum.py similarity index 100% rename from Easy/product-sum.py rename to python/Easy/product-sum.py diff --git a/Easy/remove-duplicates-from-linked-list.py b/python/Easy/remove-duplicates-from-linked-list.py similarity index 100% rename from Easy/remove-duplicates-from-linked-list.py rename to python/Easy/remove-duplicates-from-linked-list.py diff --git a/Easy/run-length-encoding.py b/python/Easy/run-length-encoding.py similarity index 100% rename from Easy/run-length-encoding.py rename to python/Easy/run-length-encoding.py diff --git a/Easy/selection-sort.py b/python/Easy/selection-sort.py similarity index 100% rename from Easy/selection-sort.py rename to python/Easy/selection-sort.py diff --git a/Easy/sorted-square-array.py b/python/Easy/sorted-square-array.py similarity index 100% rename from Easy/sorted-square-array.py rename to python/Easy/sorted-square-array.py diff --git a/Easy/tandem-bicycle.py b/python/Easy/tandem-bicycle.py similarity index 100% rename from Easy/tandem-bicycle.py rename to python/Easy/tandem-bicycle.py diff --git a/Easy/tournament-winner.py b/python/Easy/tournament-winner.py similarity index 100% rename from Easy/tournament-winner.py rename to python/Easy/tournament-winner.py diff --git a/Easy/twoNumberSum.py b/python/Easy/twoNumberSum.py similarity index 100% rename from Easy/twoNumberSum.py rename to python/Easy/twoNumberSum.py diff --git a/Easy/validate-subsequence.py b/python/Easy/validate-subsequence.py similarity index 100% rename from Easy/validate-subsequence.py rename to python/Easy/validate-subsequence.py diff --git a/Hard/ambiguous-measurements.py b/python/Hard/ambiguous-measurements.py similarity index 100% rename from Hard/ambiguous-measurements.py rename to python/Hard/ambiguous-measurements.py diff --git a/Hard/boggle-board.py b/python/Hard/boggle-board.py similarity index 100% rename from Hard/boggle-board.py rename to python/Hard/boggle-board.py diff --git a/Hard/continuous-median.py b/python/Hard/continuous-median.py similarity index 100% rename from Hard/continuous-median.py rename to python/Hard/continuous-median.py diff --git a/Hard/dijkstra-algorithm.py b/python/Hard/dijkstra-algorithm.py similarity index 100% rename from Hard/dijkstra-algorithm.py rename to python/Hard/dijkstra-algorithm.py diff --git a/Hard/disk-stacking.py b/python/Hard/disk-stacking.py similarity index 100% rename from Hard/disk-stacking.py rename to python/Hard/disk-stacking.py diff --git a/Hard/find-loop.py b/python/Hard/find-loop.py similarity index 100% rename from Hard/find-loop.py rename to python/Hard/find-loop.py diff --git a/Hard/find-nodes-distance-k.py b/python/Hard/find-nodes-distance-k.py similarity index 100% rename from Hard/find-nodes-distance-k.py rename to python/Hard/find-nodes-distance-k.py diff --git a/Hard/four-number-sum.py b/python/Hard/four-number-sum.py similarity index 100% rename from Hard/four-number-sum.py rename to python/Hard/four-number-sum.py diff --git a/Hard/generate-div-tags.py b/python/Hard/generate-div-tags.py similarity index 100% rename from Hard/generate-div-tags.py rename to python/Hard/generate-div-tags.py diff --git a/Hard/glob-matching.py b/python/Hard/glob-matching.py similarity index 100% rename from Hard/glob-matching.py rename to python/Hard/glob-matching.py diff --git a/Hard/heap-sort.py b/python/Hard/heap-sort.py similarity index 100% rename from Hard/heap-sort.py rename to python/Hard/heap-sort.py diff --git a/Hard/index-equals-value.py b/python/Hard/index-equals-value.py similarity index 100% rename from Hard/index-equals-value.py rename to python/Hard/index-equals-value.py diff --git a/Hard/interweaving-strings.py b/python/Hard/interweaving-strings.py similarity index 100% rename from Hard/interweaving-strings.py rename to python/Hard/interweaving-strings.py diff --git a/Hard/inverted-bisection.py b/python/Hard/inverted-bisection.py similarity index 100% rename from Hard/inverted-bisection.py rename to python/Hard/inverted-bisection.py diff --git a/Hard/knapsack-problem.py b/python/Hard/knapsack-problem.py similarity index 100% rename from Hard/knapsack-problem.py rename to python/Hard/knapsack-problem.py diff --git a/Hard/laptop-rentals.py b/python/Hard/laptop-rentals.py similarity index 100% rename from Hard/laptop-rentals.py rename to python/Hard/laptop-rentals.py diff --git a/Hard/largest-range.py b/python/Hard/largest-range.py similarity index 100% rename from Hard/largest-range.py rename to python/Hard/largest-range.py diff --git a/Hard/largest-rectangle-under-skyline.py b/python/Hard/largest-rectangle-under-skyline.py similarity index 100% rename from Hard/largest-rectangle-under-skyline.py rename to python/Hard/largest-rectangle-under-skyline.py diff --git a/Hard/longest-common-subsequence.py b/python/Hard/longest-common-subsequence.py similarity index 100% rename from Hard/longest-common-subsequence.py rename to python/Hard/longest-common-subsequence.py diff --git a/Hard/longest-substring-without-duplication.py b/python/Hard/longest-substring-without-duplication.py similarity index 100% rename from Hard/longest-substring-without-duplication.py rename to python/Hard/longest-substring-without-duplication.py diff --git a/Hard/lowest-common-manager.py b/python/Hard/lowest-common-manager.py similarity index 100% rename from Hard/lowest-common-manager.py rename to python/Hard/lowest-common-manager.py diff --git a/Hard/max-path-sum-binary-trees.py b/python/Hard/max-path-sum-binary-trees.py similarity index 100% rename from Hard/max-path-sum-binary-trees.py rename to python/Hard/max-path-sum-binary-trees.py diff --git a/Hard/max-sum-increasing-subsequence.py b/python/Hard/max-sum-increasing-subsequence.py similarity index 100% rename from Hard/max-sum-increasing-subsequence.py rename to python/Hard/max-sum-increasing-subsequence.py diff --git a/Hard/maximize-expression.py b/python/Hard/maximize-expression.py similarity index 100% rename from Hard/maximize-expression.py rename to python/Hard/maximize-expression.py diff --git a/Hard/maximum-sum-submatrix.py b/python/Hard/maximum-sum-submatrix.py similarity index 100% rename from Hard/maximum-sum-submatrix.py rename to python/Hard/maximum-sum-submatrix.py diff --git a/Hard/merge-linked-list.py b/python/Hard/merge-linked-list.py similarity index 100% rename from Hard/merge-linked-list.py rename to python/Hard/merge-linked-list.py diff --git a/Hard/min-number-of-jumps.py b/python/Hard/min-number-of-jumps.py similarity index 100% rename from Hard/min-number-of-jumps.py rename to python/Hard/min-number-of-jumps.py diff --git a/Hard/min-rewards.py b/python/Hard/min-rewards.py similarity index 100% rename from Hard/min-rewards.py rename to python/Hard/min-rewards.py diff --git a/Hard/multi-string-search.py b/python/Hard/multi-string-search.py similarity index 100% rename from Hard/multi-string-search.py rename to python/Hard/multi-string-search.py diff --git a/Hard/numbers-pi.py b/python/Hard/numbers-pi.py similarity index 100% rename from Hard/numbers-pi.py rename to python/Hard/numbers-pi.py diff --git a/Hard/pattern-matcher.py b/python/Hard/pattern-matcher.py similarity index 100% rename from Hard/pattern-matcher.py rename to python/Hard/pattern-matcher.py diff --git a/Hard/quick-sort.py b/python/Hard/quick-sort.py similarity index 100% rename from Hard/quick-sort.py rename to python/Hard/quick-sort.py diff --git a/Hard/quickselect.py b/python/Hard/quickselect.py similarity index 100% rename from Hard/quickselect.py rename to python/Hard/quickselect.py diff --git a/Hard/radix-sort.py b/python/Hard/radix-sort.py similarity index 100% rename from Hard/radix-sort.py rename to python/Hard/radix-sort.py diff --git a/Hard/reverse-linked-list.py b/python/Hard/reverse-linked-list.py similarity index 100% rename from Hard/reverse-linked-list.py rename to python/Hard/reverse-linked-list.py diff --git a/Hard/same-bsts.py b/python/Hard/same-bsts.py similarity index 100% rename from Hard/same-bsts.py rename to python/Hard/same-bsts.py diff --git a/Hard/search-for-range.py b/python/Hard/search-for-range.py similarity index 100% rename from Hard/search-for-range.py rename to python/Hard/search-for-range.py diff --git a/Hard/shift-linked-list.py b/python/Hard/shift-linked-list.py similarity index 100% rename from Hard/shift-linked-list.py rename to python/Hard/shift-linked-list.py diff --git a/Hard/shifted-binary-search.py b/python/Hard/shifted-binary-search.py similarity index 100% rename from Hard/shifted-binary-search.py rename to python/Hard/shifted-binary-search.py diff --git a/Hard/shorten-path.py b/python/Hard/shorten-path.py similarity index 100% rename from Hard/shorten-path.py rename to python/Hard/shorten-path.py diff --git a/Hard/solve-sudoku.py b/python/Hard/solve-sudoku.py similarity index 100% rename from Hard/solve-sudoku.py rename to python/Hard/solve-sudoku.py diff --git a/Hard/sort-k-sorted-array.py b/python/Hard/sort-k-sorted-array.py similarity index 100% rename from Hard/sort-k-sorted-array.py rename to python/Hard/sort-k-sorted-array.py diff --git a/Hard/special-strings.py b/python/Hard/special-strings.py similarity index 100% rename from Hard/special-strings.py rename to python/Hard/special-strings.py diff --git a/Hard/subarray-sort.py b/python/Hard/subarray-sort.py similarity index 100% rename from Hard/subarray-sort.py rename to python/Hard/subarray-sort.py diff --git a/Hard/topological-sort.py b/python/Hard/topological-sort.py similarity index 100% rename from Hard/topological-sort.py rename to python/Hard/topological-sort.py diff --git a/Hard/underscorify-substring.py b/python/Hard/underscorify-substring.py similarity index 100% rename from Hard/underscorify-substring.py rename to python/Hard/underscorify-substring.py diff --git a/Hard/validate-three-nodes.py b/python/Hard/validate-three-nodes.py similarity index 100% rename from Hard/validate-three-nodes.py rename to python/Hard/validate-three-nodes.py diff --git a/Hard/water-area.py b/python/Hard/water-area.py similarity index 100% rename from Hard/water-area.py rename to python/Hard/water-area.py diff --git a/Hard/zigzag-traverse.py b/python/Hard/zigzag-traverse.py similarity index 100% rename from Hard/zigzag-traverse.py rename to python/Hard/zigzag-traverse.py diff --git a/Medium/array-of-products.py b/python/Medium/array-of-products.py similarity index 100% rename from Medium/array-of-products.py rename to python/Medium/array-of-products.py diff --git a/Medium/balanced-brackets.py b/python/Medium/balanced-brackets.py similarity index 100% rename from Medium/balanced-brackets.py rename to python/Medium/balanced-brackets.py diff --git a/Medium/binary-tree-diameter.py b/python/Medium/binary-tree-diameter.py similarity index 100% rename from Medium/binary-tree-diameter.py rename to python/Medium/binary-tree-diameter.py diff --git a/Medium/breadth-first-search.py b/python/Medium/breadth-first-search.py similarity index 100% rename from Medium/breadth-first-search.py rename to python/Medium/breadth-first-search.py diff --git a/Medium/bst-construction.py b/python/Medium/bst-construction.py similarity index 100% rename from Medium/bst-construction.py rename to python/Medium/bst-construction.py diff --git a/Medium/bst-traversal.py b/python/Medium/bst-traversal.py similarity index 100% rename from Medium/bst-traversal.py rename to python/Medium/bst-traversal.py diff --git a/Medium/cycle-in-graph.py b/python/Medium/cycle-in-graph.py similarity index 100% rename from Medium/cycle-in-graph.py rename to python/Medium/cycle-in-graph.py diff --git a/Medium/degrees-of-separation.py b/python/Medium/degrees-of-separation.py similarity index 100% rename from Medium/degrees-of-separation.py rename to python/Medium/degrees-of-separation.py diff --git a/Medium/find-kth-largest-value-in-bst.py b/python/Medium/find-kth-largest-value-in-bst.py similarity index 100% rename from Medium/find-kth-largest-value-in-bst.py rename to python/Medium/find-kth-largest-value-in-bst.py diff --git a/Medium/find-successor.py b/python/Medium/find-successor.py similarity index 100% rename from Medium/find-successor.py rename to python/Medium/find-successor.py diff --git a/Medium/first-duplicate-value.py b/python/Medium/first-duplicate-value.py similarity index 100% rename from Medium/first-duplicate-value.py rename to python/Medium/first-duplicate-value.py diff --git a/Medium/group-anagrams.py b/python/Medium/group-anagrams.py similarity index 100% rename from Medium/group-anagrams.py rename to python/Medium/group-anagrams.py diff --git a/Medium/height-balanced-binary-tree.py b/python/Medium/height-balanced-binary-tree.py similarity index 100% rename from Medium/height-balanced-binary-tree.py rename to python/Medium/height-balanced-binary-tree.py diff --git a/Medium/invert-binary-tree.py b/python/Medium/invert-binary-tree.py similarity index 100% rename from Medium/invert-binary-tree.py rename to python/Medium/invert-binary-tree.py diff --git a/Medium/kadane-algorithm.py b/python/Medium/kadane-algorithm.py similarity index 100% rename from Medium/kadane-algorithm.py rename to python/Medium/kadane-algorithm.py diff --git a/Medium/levenshtein-distance.py b/python/Medium/levenshtein-distance.py similarity index 100% rename from Medium/levenshtein-distance.py rename to python/Medium/levenshtein-distance.py diff --git a/Medium/linked-list-construction.py b/python/Medium/linked-list-construction.py similarity index 100% rename from Medium/linked-list-construction.py rename to python/Medium/linked-list-construction.py diff --git a/Medium/longest-palindromic-substring.py b/python/Medium/longest-palindromic-substring.py similarity index 100% rename from Medium/longest-palindromic-substring.py rename to python/Medium/longest-palindromic-substring.py diff --git a/Medium/longest-peak.py b/python/Medium/longest-peak.py similarity index 100% rename from Medium/longest-peak.py rename to python/Medium/longest-peak.py diff --git a/Medium/max-subset-sum-no-adjacent.py b/python/Medium/max-subset-sum-no-adjacent.py similarity index 100% rename from Medium/max-subset-sum-no-adjacent.py rename to python/Medium/max-subset-sum-no-adjacent.py diff --git a/Medium/merge-overlapping-intervals.py b/python/Medium/merge-overlapping-intervals.py similarity index 100% rename from Medium/merge-overlapping-intervals.py rename to python/Medium/merge-overlapping-intervals.py diff --git a/Medium/min-heap-construction.py b/python/Medium/min-heap-construction.py similarity index 100% rename from Medium/min-heap-construction.py rename to python/Medium/min-heap-construction.py diff --git a/Medium/min-height-BST.py b/python/Medium/min-height-BST.py similarity index 100% rename from Medium/min-height-BST.py rename to python/Medium/min-height-BST.py diff --git a/Medium/min-max-stack-construction.py b/python/Medium/min-max-stack-construction.py similarity index 100% rename from Medium/min-max-stack-construction.py rename to python/Medium/min-max-stack-construction.py diff --git a/Medium/min-number-of-coins-for-change.py b/python/Medium/min-number-of-coins-for-change.py similarity index 100% rename from Medium/min-number-of-coins-for-change.py rename to python/Medium/min-number-of-coins-for-change.py diff --git a/Medium/minimum-characters-for-words.py b/python/Medium/minimum-characters-for-words.py similarity index 100% rename from Medium/minimum-characters-for-words.py rename to python/Medium/minimum-characters-for-words.py diff --git a/Medium/minimum-passes-of-matrix.py b/python/Medium/minimum-passes-of-matrix.py similarity index 100% rename from Medium/minimum-passes-of-matrix.py rename to python/Medium/minimum-passes-of-matrix.py diff --git a/Medium/monotonic-array.py b/python/Medium/monotonic-array.py similarity index 100% rename from Medium/monotonic-array.py rename to python/Medium/monotonic-array.py diff --git a/Medium/move-element-to-end.py b/python/Medium/move-element-to-end.py similarity index 100% rename from Medium/move-element-to-end.py rename to python/Medium/move-element-to-end.py diff --git a/Medium/next-greater-element.py b/python/Medium/next-greater-element.py similarity index 100% rename from Medium/next-greater-element.py rename to python/Medium/next-greater-element.py diff --git a/Medium/number-of-ways-to-traverse-graph.py b/python/Medium/number-of-ways-to-traverse-graph.py similarity index 100% rename from Medium/number-of-ways-to-traverse-graph.py rename to python/Medium/number-of-ways-to-traverse-graph.py diff --git a/Medium/permutations.py b/python/Medium/permutations.py similarity index 100% rename from Medium/permutations.py rename to python/Medium/permutations.py diff --git a/Medium/phone-number-mnemonics.py b/python/Medium/phone-number-mnemonics.py similarity index 100% rename from Medium/phone-number-mnemonics.py rename to python/Medium/phone-number-mnemonics.py diff --git a/Medium/powerset.py b/python/Medium/powerset.py similarity index 100% rename from Medium/powerset.py rename to python/Medium/powerset.py diff --git a/Medium/reconstruct-bst.py b/python/Medium/reconstruct-bst.py similarity index 100% rename from Medium/reconstruct-bst.py rename to python/Medium/reconstruct-bst.py diff --git a/Medium/remove-islands.py b/python/Medium/remove-islands.py similarity index 100% rename from Medium/remove-islands.py rename to python/Medium/remove-islands.py diff --git a/Medium/remove-kth-node-from-end.py b/python/Medium/remove-kth-node-from-end.py similarity index 100% rename from Medium/remove-kth-node-from-end.py rename to python/Medium/remove-kth-node-from-end.py diff --git a/Medium/reverse-words-in-string.py b/python/Medium/reverse-words-in-string.py similarity index 100% rename from Medium/reverse-words-in-string.py rename to python/Medium/reverse-words-in-string.py diff --git a/Medium/river-sizes.py b/python/Medium/river-sizes.py similarity index 100% rename from Medium/river-sizes.py rename to python/Medium/river-sizes.py diff --git a/Medium/search-in-sorted-matrix.py b/python/Medium/search-in-sorted-matrix.py similarity index 100% rename from Medium/search-in-sorted-matrix.py rename to python/Medium/search-in-sorted-matrix.py diff --git a/Medium/single-cycle-check.py b/python/Medium/single-cycle-check.py similarity index 100% rename from Medium/single-cycle-check.py rename to python/Medium/single-cycle-check.py diff --git a/Medium/smallest-difference.py b/python/Medium/smallest-difference.py similarity index 100% rename from Medium/smallest-difference.py rename to python/Medium/smallest-difference.py diff --git a/Medium/sort-stack.py b/python/Medium/sort-stack.py similarity index 100% rename from Medium/sort-stack.py rename to python/Medium/sort-stack.py diff --git a/Medium/spiral-traverse.py b/python/Medium/spiral-traverse.py similarity index 100% rename from Medium/spiral-traverse.py rename to python/Medium/spiral-traverse.py diff --git a/Medium/staircase-traversal.py b/python/Medium/staircase-traversal.py similarity index 100% rename from Medium/staircase-traversal.py rename to python/Medium/staircase-traversal.py diff --git a/Medium/suffix-trie-construction.py b/python/Medium/suffix-trie-construction.py similarity index 100% rename from Medium/suffix-trie-construction.py rename to python/Medium/suffix-trie-construction.py diff --git a/Medium/sum-of-linked-lists.py b/python/Medium/sum-of-linked-lists.py similarity index 100% rename from Medium/sum-of-linked-lists.py rename to python/Medium/sum-of-linked-lists.py diff --git a/Medium/sunset-views.py b/python/Medium/sunset-views.py similarity index 100% rename from Medium/sunset-views.py rename to python/Medium/sunset-views.py diff --git a/Medium/task-assignment.py b/python/Medium/task-assignment.py similarity index 100% rename from Medium/task-assignment.py rename to python/Medium/task-assignment.py diff --git a/Medium/three-number-sort.py b/python/Medium/three-number-sort.py similarity index 100% rename from Medium/three-number-sort.py rename to python/Medium/three-number-sort.py diff --git a/Medium/three-number-sum.py b/python/Medium/three-number-sum.py similarity index 100% rename from Medium/three-number-sum.py rename to python/Medium/three-number-sum.py diff --git a/Medium/valid-ip-addresses.py b/python/Medium/valid-ip-addresses.py similarity index 100% rename from Medium/valid-ip-addresses.py rename to python/Medium/valid-ip-addresses.py diff --git a/Medium/valid-starting-city.py b/python/Medium/valid-starting-city.py similarity index 100% rename from Medium/valid-starting-city.py rename to python/Medium/valid-starting-city.py diff --git a/Medium/validate-bst.py b/python/Medium/validate-bst.py similarity index 100% rename from Medium/validate-bst.py rename to python/Medium/validate-bst.py diff --git a/Medium/ways-to-make-change.py b/python/Medium/ways-to-make-change.py similarity index 100% rename from Medium/ways-to-make-change.py rename to python/Medium/ways-to-make-change.py diff --git a/Medium/youngest-common-ancestor.py b/python/Medium/youngest-common-ancestor.py similarity index 100% rename from Medium/youngest-common-ancestor.py rename to python/Medium/youngest-common-ancestor.py diff --git a/Very Hard/A-star-algorithm.py b/python/Very Hard/A-star-algorithm.py similarity index 100% rename from Very Hard/A-star-algorithm.py rename to python/Very Hard/A-star-algorithm.py diff --git a/Very Hard/LRU-cache.py b/python/Very Hard/LRU-cache.py similarity index 100% rename from Very Hard/LRU-cache.py rename to python/Very Hard/LRU-cache.py diff --git a/Very Hard/airport-connections.py b/python/Very Hard/airport-connections.py similarity index 100% rename from Very Hard/airport-connections.py rename to python/Very Hard/airport-connections.py diff --git a/Very Hard/all-kinds-of-node-depths.py b/python/Very Hard/all-kinds-of-node-depths.py similarity index 100% rename from Very Hard/all-kinds-of-node-depths.py rename to python/Very Hard/all-kinds-of-node-depths.py diff --git a/Very Hard/apartment-hunting.py b/python/Very Hard/apartment-hunting.py similarity index 100% rename from Very Hard/apartment-hunting.py rename to python/Very Hard/apartment-hunting.py diff --git a/Very Hard/calendar-matching.py b/python/Very Hard/calendar-matching.py similarity index 100% rename from Very Hard/calendar-matching.py rename to python/Very Hard/calendar-matching.py diff --git a/Very Hard/compare-leaf-traversal.py b/python/Very Hard/compare-leaf-traversal.py similarity index 100% rename from Very Hard/compare-leaf-traversal.py rename to python/Very Hard/compare-leaf-traversal.py diff --git a/Very Hard/count-inversions.py b/python/Very Hard/count-inversions.py similarity index 100% rename from Very Hard/count-inversions.py rename to python/Very Hard/count-inversions.py diff --git a/Very Hard/detect-arbitrage.py b/python/Very Hard/detect-arbitrage.py similarity index 100% rename from Very Hard/detect-arbitrage.py rename to python/Very Hard/detect-arbitrage.py diff --git a/Very Hard/flatten-binary-tree.py b/python/Very Hard/flatten-binary-tree.py similarity index 100% rename from Very Hard/flatten-binary-tree.py rename to python/Very Hard/flatten-binary-tree.py diff --git a/Very Hard/iterative-inorder-traversal.py b/python/Very Hard/iterative-inorder-traversal.py similarity index 100% rename from Very Hard/iterative-inorder-traversal.py rename to python/Very Hard/iterative-inorder-traversal.py diff --git a/Very Hard/knuth-morris-pratt-algorithm.py b/python/Very Hard/knuth-morris-pratt-algorithm.py similarity index 100% rename from Very Hard/knuth-morris-pratt-algorithm.py rename to python/Very Hard/knuth-morris-pratt-algorithm.py diff --git a/Very Hard/line-through-points.py b/python/Very Hard/line-through-points.py similarity index 100% rename from Very Hard/line-through-points.py rename to python/Very Hard/line-through-points.py diff --git a/Very Hard/linked-list-palindrome.py b/python/Very Hard/linked-list-palindrome.py similarity index 100% rename from Very Hard/linked-list-palindrome.py rename to python/Very Hard/linked-list-palindrome.py diff --git a/Very Hard/longest-balanced-substring.py b/python/Very Hard/longest-balanced-substring.py similarity index 100% rename from Very Hard/longest-balanced-substring.py rename to python/Very Hard/longest-balanced-substring.py diff --git a/Very Hard/longest-increasing-subsequence.py b/python/Very Hard/longest-increasing-subsequence.py similarity index 100% rename from Very Hard/longest-increasing-subsequence.py rename to python/Very Hard/longest-increasing-subsequence.py diff --git a/Very Hard/longest-string-chain.py b/python/Very Hard/longest-string-chain.py similarity index 100% rename from Very Hard/longest-string-chain.py rename to python/Very Hard/longest-string-chain.py diff --git a/Very Hard/max-profits-with-k-transactions.py b/python/Very Hard/max-profits-with-k-transactions.py similarity index 100% rename from Very Hard/max-profits-with-k-transactions.py rename to python/Very Hard/max-profits-with-k-transactions.py diff --git a/Very Hard/merge-sort.py b/python/Very Hard/merge-sort.py similarity index 100% rename from Very Hard/merge-sort.py rename to python/Very Hard/merge-sort.py diff --git a/Very Hard/merge-sorted-arrays.py b/python/Very Hard/merge-sorted-arrays.py similarity index 100% rename from Very Hard/merge-sorted-arrays.py rename to python/Very Hard/merge-sorted-arrays.py diff --git a/Very Hard/minimum-area-rectangle.py b/python/Very Hard/minimum-area-rectangle.py similarity index 100% rename from Very Hard/minimum-area-rectangle.py rename to python/Very Hard/minimum-area-rectangle.py diff --git a/Very Hard/node-swap.py b/python/Very Hard/node-swap.py similarity index 100% rename from Very Hard/node-swap.py rename to python/Very Hard/node-swap.py diff --git a/Very Hard/non-attacking-queens.py b/python/Very Hard/non-attacking-queens.py similarity index 100% rename from Very Hard/non-attacking-queens.py rename to python/Very Hard/non-attacking-queens.py diff --git a/Very Hard/number-of-binary-tree-topologies.py b/python/Very Hard/number-of-binary-tree-topologies.py similarity index 100% rename from Very Hard/number-of-binary-tree-topologies.py rename to python/Very Hard/number-of-binary-tree-topologies.py diff --git a/Very Hard/palindrome-partitioning-min-cuts.py b/python/Very Hard/palindrome-partitioning-min-cuts.py similarity index 100% rename from Very Hard/palindrome-partitioning-min-cuts.py rename to python/Very Hard/palindrome-partitioning-min-cuts.py diff --git a/Very Hard/rearrange-linked-list.py b/python/Very Hard/rearrange-linked-list.py similarity index 100% rename from Very Hard/rearrange-linked-list.py rename to python/Very Hard/rearrange-linked-list.py diff --git a/Very Hard/rectangle-mania.py b/python/Very Hard/rectangle-mania.py similarity index 100% rename from Very Hard/rectangle-mania.py rename to python/Very Hard/rectangle-mania.py diff --git a/Very Hard/right-sibling-tree.py b/python/Very Hard/right-sibling-tree.py similarity index 100% rename from Very Hard/right-sibling-tree.py rename to python/Very Hard/right-sibling-tree.py diff --git a/Very Hard/right-smaller-than.py b/python/Very Hard/right-smaller-than.py similarity index 100% rename from Very Hard/right-smaller-than.py rename to python/Very Hard/right-smaller-than.py diff --git a/Very Hard/smallest-substring-containing.py b/python/Very Hard/smallest-substring-containing.py similarity index 100% rename from Very Hard/smallest-substring-containing.py rename to python/Very Hard/smallest-substring-containing.py diff --git a/Very Hard/square-of-zeroes.py b/python/Very Hard/square-of-zeroes.py similarity index 100% rename from Very Hard/square-of-zeroes.py rename to python/Very Hard/square-of-zeroes.py diff --git a/Very Hard/two-edge-connected-graph.py b/python/Very Hard/two-edge-connected-graph.py similarity index 100% rename from Very Hard/two-edge-connected-graph.py rename to python/Very Hard/two-edge-connected-graph.py diff --git a/Very Hard/waterfall-streams.py b/python/Very Hard/waterfall-streams.py similarity index 100% rename from Very Hard/waterfall-streams.py rename to python/Very Hard/waterfall-streams.py diff --git a/Very Hard/zip-linked-list.py b/python/Very Hard/zip-linked-list.py similarity index 100% rename from Very Hard/zip-linked-list.py rename to python/Very Hard/zip-linked-list.py From 7c9b6e9b883c77c574165db7af36d904b39d54e5 Mon Sep 17 00:00:00 2001 From: Sanzay Dahal Date: Sun, 26 Mar 2023 15:51:30 +1100 Subject: [PATCH 2/2] Add javaScript solutions --- javaScript/easy/twoNumberSum.js | 31 +++++ javaScript/hard/patternMatcher.js | 76 +++++++++++++ javaScript/hard/solveSudoku.js | 69 ++++++++++++ javaScript/medium/KadanesAlgorithm.js | 24 ++++ javaScript/medium/binaryTreeDiameter.js | 30 +++++ javaScript/medium/bstTraversal.js | 36 ++++++ javaScript/medium/invertBinaryTree.js | 27 +++++ javaScript/medium/kthLargestValueBST.js | 57 ++++++++++ javaScript/medium/maxProductSubarray.js | 44 ++++++++ javaScript/medium/maxSubsetSumNoAdjacent.js | 18 +++ javaScript/medium/minHeightBst.js | 100 +++++++++++++++++ javaScript/medium/phoneNumberMnemonics.js | 52 +++++++++ javaScript/medium/reconstructBST.js | 53 +++++++++ javaScript/medium/suffixTrieConstruction.js | 49 ++++++++ javaScript/medium/threeNumberSum.js | 23 ++++ javaScript/very-hard/calendarMatching.js | 118 ++++++++++++++++++++ 16 files changed, 807 insertions(+) create mode 100644 javaScript/easy/twoNumberSum.js create mode 100644 javaScript/hard/patternMatcher.js create mode 100644 javaScript/hard/solveSudoku.js create mode 100644 javaScript/medium/KadanesAlgorithm.js create mode 100644 javaScript/medium/binaryTreeDiameter.js create mode 100644 javaScript/medium/bstTraversal.js create mode 100644 javaScript/medium/invertBinaryTree.js create mode 100644 javaScript/medium/kthLargestValueBST.js create mode 100644 javaScript/medium/maxProductSubarray.js create mode 100644 javaScript/medium/maxSubsetSumNoAdjacent.js create mode 100644 javaScript/medium/minHeightBst.js create mode 100644 javaScript/medium/phoneNumberMnemonics.js create mode 100644 javaScript/medium/reconstructBST.js create mode 100644 javaScript/medium/suffixTrieConstruction.js create mode 100644 javaScript/medium/threeNumberSum.js create mode 100644 javaScript/very-hard/calendarMatching.js diff --git a/javaScript/easy/twoNumberSum.js b/javaScript/easy/twoNumberSum.js new file mode 100644 index 0000000..3498649 --- /dev/null +++ b/javaScript/easy/twoNumberSum.js @@ -0,0 +1,31 @@ +// SOLUTION 1: +// O(n) time | O(n) space +function twoNumberSum(array, targetSum) { + let obj = {}; + + for (let x of array) { + if (obj[targetSum - x]) { + return [targetSum - x, x]; + } else { + obj[x] = true; + } + } + + return []; +} + +// SOLUTION 2: +// O(nlog(n)) | O(1) space +function twoNumberSum(array, targetSum) { + let obj = {}; + + for (let x of array) { + if (obj[targetSum - x]) { + return [targetSum - x, x]; + } else { + obj[x] = true; + } + } + + return []; +} diff --git a/javaScript/hard/patternMatcher.js b/javaScript/hard/patternMatcher.js new file mode 100644 index 0000000..267094b --- /dev/null +++ b/javaScript/hard/patternMatcher.js @@ -0,0 +1,76 @@ +// pattern = "xxyxxy" +// string = "gogopowerrangergogopowerranger" +// output: ["go", "powerranger"] + +function patternMatcher(pattern, string) { + if (pattern.length > string.length) { + return []; + } + + const newPattern = getNewPattern(pattern); + const hasPatternSwitched = pattern[0] !== newPattern[0]; + + const counts = { x: 0, y: 0 }; + + const firstYIndex = getCountsAndFirstYIndex(newPattern, counts); + + if (counts.y !== 0) { + for (let lengOfX = 1; lengOfX <= string.length; lengOfX++) { + const lengOfY = (string.length - lengOfX * counts.x) / counts.y; + if (lengOfY <= 0 || lengOfY % 1 !== 0) { + continue; + } + + const x = string.slice(0, lengOfX); + const yPosition = firstYIndex * lengOfX; + const y = string.slice(yPosition, yPosition + lengOfY); + + const potentialMatch = newPattern + .map((char) => (char === 'x' ? x : y)) + .join(''); + if (potentialMatch === string) { + return hasPatternSwitched ? [y, x] : [x, y]; + } + } + } else { + const lengOfX = string.length / counts.x; + if (lengOfX % 1 !== 0) { + return []; + } + + const x = string.slice(0, lengOfX); + + const potentialMatch = newPattern.map(() => x).join(''); + + if (potentialMatch === string) { + return hasPatternSwitched ? ['', x] : [x, '']; + } + } + + return []; +} + +function getNewPattern(pattern) { + let patternArray = pattern.split(''); + if (patternArray[0] === 'x') { + return patternArray; + } + + return patternArray.map((item) => (item === 'x' ? 'y' : 'x')); +} + +function getCountsAndFirstYIndex(newPattern, counts) { + let firstYIndex = null; + newPattern.map((item, i) => { + if (item === 'y' && firstYIndex === null) { + firstYIndex = i; + } + + counts[item]++; + }); + + return firstYIndex; +} + +const result = patternMatcher('xxyxxy', 'gogopowerrangergogopowerranger'); +console.log(result); diff --git a/javaScript/hard/solveSudoku.js b/javaScript/hard/solveSudoku.js new file mode 100644 index 0000000..d59bed1 --- /dev/null +++ b/javaScript/hard/solveSudoku.js @@ -0,0 +1,69 @@ +function solveSudoku(board) { + // Write your code here. + solveSudokuPartial(board, 0, 0); + return board; +} + +function solveSudokuPartial(board, row, col) { + let currentRow = row; + let currentCol = col; + + if (currentCol === board[currentRow].length) { + currentRow++; + currentCol = 0; + + if (currentRow === board.length) return true; + } + + if (board[currentRow][currentCol] === 0) { + return trialAllDigits(board, currentRow, currentCol); + } + + return solveSudokuPartial(board, currentRow, currentCol + 1); +} + +function trialAllDigits(board, row, col) { + for (let digit = 1; digit < 10; digit++) { + if (isNumberValidAtPosition(board, row, col, digit)) { + board[row][col] = digit; + if (solveSudokuPartial(board, row, col + 1)) return true; + } + } + + board[row][col] = 0; + return false; +} + +function isNumberValidAtPosition(board, row, col, value) { + return !( + hasNumberInRow(board, row, value) || + hasNumberInCol(board, col, value) || + hasNumberInBox(board, row, col, value) + ); +} + +function hasNumberInRow(board, row, value) { + return board[row].includes(value); +} + +function hasNumberInCol(board, col, value) { + return board.map((r) => r[col]).includes(value); +} + +function hasNumberInBox(board, row, col, value) { + const rowStart = Math.floor(row / 3) * 3; + const colStart = Math.floor(col / 3) * 3; + + for (let rowIdx = 0; rowIdx < 3; rowIdx++) { + for (let colIdx = 0; colIdx < 3; colIdx++) { + const rowToCheck = rowStart + rowIdx; + const colToCheck = colStart + colIdx; + const currentValue = board[rowToCheck][colToCheck]; + if (currentValue === value) return true; + } + } + + return false; +} +// Do not edit the line below. +exports.solveSudoku = solveSudoku; diff --git a/javaScript/medium/KadanesAlgorithm.js b/javaScript/medium/KadanesAlgorithm.js new file mode 100644 index 0000000..4addf6d --- /dev/null +++ b/javaScript/medium/KadanesAlgorithm.js @@ -0,0 +1,24 @@ +// Write a function that takes in a non-empty array of integers and returns the +// maximum sum that can be obtained by summing up all of the integers in a +// non-empty subarray of the input array. A subarray must only contain adjacent +// numbers (numbers next to each other in the input array). + +// Sample input = [3, 5, -9, 1, 3, -2, 3, 4, 7, 2, -9, 6, 3, 1, -5, 4] +// Sample output = 19 // [1, 3, -2, 3, 4, 7, 2, -9, 6, 3, 1] + +function kadanesAlgorithm(array) { + let maxEndingHere = array[0]; + let maxSoFar = array[0]; + + for (let i = 1; i < array.length; i++) { + const num = array[i]; + maxEndingHere = Math.max(maxEndingHere + num, num); + maxSoFar = Math.max(maxSoFar, maxEndingHere); + } + + return maxSoFar; +} + +const input = [3, 5, -9, 1, 3, -2, 3, 4, 7, 2, -9, 6, 3, 1, -5, 4]; +const result = kadanesAlgorithm(input); +console.log(result); // 19 diff --git a/javaScript/medium/binaryTreeDiameter.js b/javaScript/medium/binaryTreeDiameter.js new file mode 100644 index 0000000..6302524 --- /dev/null +++ b/javaScript/medium/binaryTreeDiameter.js @@ -0,0 +1,30 @@ +// Space Complexity O(h), where h is the height of the tree +// Time Complexity O(n), where n is the number of nodes in the Binary tree +class BinaryTree { + constructor(value) { + this.value = value; + this.left = null; + this.right = null; + } +} + +function binaryTreeDiameter(tree) { + // Write your code here. + let diameter = 0; + function dfsHeightCalculation(node) { + if (!node) { + return 0; + } + + const leftHeight = dfsHeightCalculation(node.left, diameter); + const rightHeight = dfsHeightCalculation(node.right, diameter); + + diameter = Math.max(diameter, leftHeight + rightHeight); + + return 1 + Math.max(leftHeight, rightHeight); + } + + dfsHeightCalculation(tree); + + return diameter; +} diff --git a/javaScript/medium/bstTraversal.js b/javaScript/medium/bstTraversal.js new file mode 100644 index 0000000..fa77a78 --- /dev/null +++ b/javaScript/medium/bstTraversal.js @@ -0,0 +1,36 @@ +// O(n) time | O(n) space + +// 10 +// 5 15 +// 2 5 22 +// 1 + +function inOrderTraverse(tree, array) { + // [1, 2, 5, 5, 10, 15, 22] + if (tree !== null) { + inOrderTraverse(tree.left, array); + array.push(tree.value); + inOrderTraverse(tree.right, array); + } + return array; +} + +function preOrderTraverse(tree, array) { + // [10, 5, 2, 1, 5, 15, 22] + if (tree !== null) { + array.push(tree.value); + preOrderTraverse(tree.left, array); + preOrderTraverse(tree.right, array); + } + return array; +} + +function postOrderTraverse(tree, array) { + // [1, 2, 5, 5, 22, 15, 10] + if (tree !== null) { + postOrderTraverse(tree.left, array); + postOrderTraverse(tree.right, array); + array.push(tree.value); + } + return array; +} diff --git a/javaScript/medium/invertBinaryTree.js b/javaScript/medium/invertBinaryTree.js new file mode 100644 index 0000000..d504cfd --- /dev/null +++ b/javaScript/medium/invertBinaryTree.js @@ -0,0 +1,27 @@ +function invertBinaryTree(tree) { + // Write your code here. + if (!tree) { + return; + } + + swapLeftAndRight(tree); + invertBinaryTree(tree.left); + invertBinaryTree(tree.right); + + return tree; +} + +function swapLeftAndRight(tree) { + let tempNode = tree.left; + tree.left = tree.right; + tree.right = tempNode; +} + +// This is the class of the input binary tree. +class BinaryTree { + constructor(value) { + this.value = value; + this.left = null; + this.right = null; + } +} diff --git a/javaScript/medium/kthLargestValueBST.js b/javaScript/medium/kthLargestValueBST.js new file mode 100644 index 0000000..b72c785 --- /dev/null +++ b/javaScript/medium/kthLargestValueBST.js @@ -0,0 +1,57 @@ +class BST { + constructor(value) { + this.value = value; + this.left = null; + this.right = null; + } +} + +// Solution 1: +// O(n) time O(n) space +function findKthLargestValueInBst(tree, k) { + const sortedNodeValues = []; + inorderTraverse(tree, sortedNodeValues); + return sortedNodeValues[sortedNodeValues.length - k]; +} + +function inorderTraverse(node, sortedNodeValues) { + if (node === null) return; + + inorderTraverse(node.left, sortedNodeValues); + sortedNodeValues.push(node.value); + inorderTraverse(node.right, sortedNodeValues); +} + +// Solution 2: +// O(h + k) time | O(h) space - where h is the height of the tree and k is the input parameter + +class TreeInfo { + constructor(numberOfNodesVisited, latestVisitedValue) { + this.numberOfNodesVisited = numberOfNodesVisited; + this.latestVisitedValue = latestVisitedValue; + } +} + +function findKthLargestValueInBst2(tree, k) { + // Write your code here. + const treeInfo = new TreeInfo(0, -1); + reverseInorderTraverse(tree, treeInfo, k); + return treeInfo.latestVisitedValue; +} + +function reverseInorderTraverse(node, treeInfo, k) { + if (node === null || treeInfo.numberOfNodesVisited >= k) { + return; + } + reverseInorderTraverse(node.right, treeInfo, k); + if (treeInfo.numberOfNodesVisited < k) { + treeInfo.numberOfNodesVisited += 1; + treeInfo.latestVisitedValue = node.value; + + reverseInorderTraverse(node.left, treeInfo, k); + } +} + +// Do not edit the lines below. +exports.BST = BST; +exports.findKthLargestValueInBst = findKthLargestValueInBst; diff --git a/javaScript/medium/maxProductSubarray.js b/javaScript/medium/maxProductSubarray.js new file mode 100644 index 0000000..0263314 --- /dev/null +++ b/javaScript/medium/maxProductSubarray.js @@ -0,0 +1,44 @@ +/* +LEETCODE PROBLEM: + +Given an integer array nums, find a +subarray + that has the largest product, and return the product. + +The test cases are generated so that the answer will fit in a 32-bit integer. + + + +Example 1: + +Input: nums = [2,3,-2,4] +Output: 6 +Explanation: [2,3] has the largest product 6. +Example 2: + +Input: nums = [-2,0,-1] +Output: 0 +Explanation: The result cannot be 2, because [-2,-1] is not a subarray. +*/ + +function maxProduct(nums) { + let currentMaxProduct = nums[0]; + let currentMinProduct = nums[0]; + let result = nums[0]; + + for (let i = 1; i < nums.length; i++) { + const num = nums[i]; + const tempMaxProduct = currentMaxProduct * num; + + currentMaxProduct = Math.max(tempMaxProduct, currentMinProduct * num, num); + currentMinProduct = Math.min(tempMaxProduct, currentMinProduct * num, num); + + result = Math.max(result, currentMaxProduct); + } + + return result; +} + +const input = [-3, -5, -2, 100, -2]; +const result = maxProduct(input); +console.log(result); // 6000 diff --git a/javaScript/medium/maxSubsetSumNoAdjacent.js b/javaScript/medium/maxSubsetSumNoAdjacent.js new file mode 100644 index 0000000..ce1937a --- /dev/null +++ b/javaScript/medium/maxSubsetSumNoAdjacent.js @@ -0,0 +1,18 @@ +// Dynamic Programming + +// O(n) time | O(n) space +function maxSubsetSumNoAdjacent(array) { + if (array.length === 0) return 0; + + let inc = array[0]; + let exc = 0; + + for (let i = 1; i < array.length; i++) { + const newInc = array[i] + exc; + const newExc = Math.max(inc, exc); + + inc = newInc; + exc = newExc; + } + return Math.max(inc, exc); +} diff --git a/javaScript/medium/minHeightBst.js b/javaScript/medium/minHeightBst.js new file mode 100644 index 0000000..a0275df --- /dev/null +++ b/javaScript/medium/minHeightBst.js @@ -0,0 +1,100 @@ +// Construct Min height BST from a sorted Array where BST class with insert method is available; + +// SOLUTION 1: O(nlog(n)) time | O(n) space + +function minHeightBst(array) { + return constructMinHeightBst(array, null, 0, array.length - 1); +} + +function constructMinHeightBst(array, bst, leftIdx, rightIdx) { + if (leftIdx > rightIdx) { + return; + } + + const midIdx = Math.floor((leftIdx + rightIdx) / 2); + const valueToAdd = array[midIdx]; + + if (bst === null) { + bst = new BST(valueToAdd); + } else { + bst.insert(valueToAdd); + } + constructMinHeightBst(array, bst, leftIdx, midIdx - 1); + constructMinHeightBst(array, bst, midIdx + 1, rightIdx); + return bst; +} + +// SOLUTION 2: O(n) time | O(n) space + +function minHeightBst2(array) { + // Write your code here. + return constructMinHeightBst2(array, null, 0, array.length - 1); +} + +function constructMinHeightBst2(array, bst, leftIdx, rightIdx) { + if (rightIdx < leftIdx) { + return; + } + + const midIdx = Math.floor((leftIdx + rightIdx) / 2); + const newBstNode = new BST(array[midIdx]); + + if (bst === null) { + bst = newBstNode; + } else { + if (bst.value > array[midIdx]) { + bst.left = newBstNode; + bst = bst.left; + } else { + bst.right = newBstNode; + bst = bst.right; + } + } + + constructMinHeightBst2(array, bst, leftIdx, rightIdx - 1); + constructMinHeightBst2(array, bst, rightIdx + 1, rightIdx); + return bst; +} + +// SOLUTION 3: O(n) time | O(n) space - Cleaner + +function minHeightBst3(array) { + return constructMinHeightBst3(array, 0, array.length - 1); +} + +function constructMinHeightBst3(array, leftIdx, rightIdx) { + if (rightIdx < leftIdx) return; + + const midIdx = Math.floor((leftIdx + rightIdx) / 2); + + const bst = new BST(array[midIdx]); + bst.left = constructMinHeightBst3(array, leftIdx, midIdx - 1); + bst.right = constructMinHeightBst3(array, midIdx + 1, rightIdx); + + return bst; +} + +// GIVEN BST class with insert() method: +class BST { + constructor(value) { + this.value = value; + this.left = null; + this.right = null; + } + + insert(value) { + if (value < this.value) { + if (this.left === null) { + this.left = new BST(value); + } else { + this.left.insert(value); + } + } else { + if (this.right === null) { + this.right = new BST(value); + } else { + this.right.insert(value); + } + } + } +} diff --git a/javaScript/medium/phoneNumberMnemonics.js b/javaScript/medium/phoneNumberMnemonics.js new file mode 100644 index 0000000..1c8a389 --- /dev/null +++ b/javaScript/medium/phoneNumberMnemonics.js @@ -0,0 +1,52 @@ +// Sample Input : phoneNumber = "1905" +// Sample Output : ["1w0j", "1w0k", "1w0l", "1x0j", .......] + +const DIGIT_LETTERS = { + 0: ['0'], + 1: ['1'], + 2: ['a', 'b', 'c'], + 3: ['d', 'e', 'f'], + 4: ['g', 'h', 'i'], + 5: ['j', 'k', 'l'], + 6: ['m', 'n', 'o'], + 7: ['p', 'q', 'r', 's'], + 8: ['t', 'u', 'v'], + 9: ['w', 'x', 'y', 'z'], +}; + +function phoneNumberMnemonics(phoneNumber) { + const currentMnemonic = Array(phoneNumber.length).fill('0'); + let mnemonicsFound = []; + + phoneNumberMnemonicsHelper(0, phoneNumber, currentMnemonic, mnemonicsFound); + + return mnemonicsFound; +} + +function phoneNumberMnemonicsHelper( + idx, + phoneNumber, + currentMnemonic, + mnemonicsFound +) { + if (idx === phoneNumber.length) { + const mnemonic = currentMnemonic.join(''); + mnemonicsFound.push(mnemonic); + } else { + const digit = phoneNumber[idx]; + const letters = DIGIT_LETTERS[digit]; + + for (letter of letters) { + currentMnemonic[idx] = letter; + phoneNumberMnemonicsHelper( + idx + 1, + phoneNumber, + currentMnemonic, + mnemonicsFound + ); + } + } +} + +const result = phoneNumberMnemonics('1905'); +console.log(result); diff --git a/javaScript/medium/reconstructBST.js b/javaScript/medium/reconstructBST.js new file mode 100644 index 0000000..837ca3d --- /dev/null +++ b/javaScript/medium/reconstructBST.js @@ -0,0 +1,53 @@ +// This is an input class. Do not edit. +class BST { + constructor(value, left = null, right = null) { + this.value = value; + this.left = left; + this.right = right; + } +} + +class BinarySearchTree { + constructor() { + this.root = null; + } + + insert(value) { + const newNode = new BST(value); + if (this.root === null) { + this.root = newNode; + } else { + let currentNode = this.root; + + while (true) { + if (value < currentNode.value) { + if (!currentNode.left) { + currentNode.left = newNode; + return this; + } + currentNode = currentNode.left; + } else { + if (!currentNode.right) { + currentNode.right = newNode; + return this; + } + currentNode = currentNode.right; + } + } + } + } +} + +function reconstructBst(preOrderTraversalValues) { + // Write your code here. + let tree = new BinarySearchTree(); + + for (let i = 0; i < preOrderTraversalValues.length; i++) { + tree.insert(preOrderTraversalValues[i]); + } + + return tree.root; +} + +const preOrderTraversalValues = [10, 4, 2, 1, 5, 17, 19, 18]; +reconstructBst(preOrderTraversalValues); diff --git a/javaScript/medium/suffixTrieConstruction.js b/javaScript/medium/suffixTrieConstruction.js new file mode 100644 index 0000000..6b04587 --- /dev/null +++ b/javaScript/medium/suffixTrieConstruction.js @@ -0,0 +1,49 @@ +class SuffixTrie { + constructor(string) { + this.root = {}; + this.endSymbol = '*'; + this.populateSuffixTrieFrom(string); + } + + populateSuffixTrieFrom(string) { + for (let i = 0; i < string.length; i++) { + this.insertSubstringStartingAt(i, string); + } + } + + insertSubstringStartingAt(i, string) { + let node = this.root; + for (let j = i; j < string.length; j++) { + const letter = string[j]; + if (!(letter in node)) { + node[letter] = {}; + } + + node = node[letter]; + } + + node[this.endSymbol] = true; + } + + contains(string) { + let node = this.root; + for (const letter of string) { + if (!(letter in node)) { + return false; + } + + node = node[letter]; + } + + return this.endSymbol in node; + } +} + +const newSuffixTrie = new SuffixTrie('babcd'); + +console.log(newSuffixTrie.contains('bab')); // false +console.log(newSuffixTrie.contains('babcd')); // true +console.log(newSuffixTrie.contains('abcd')); // true +console.log(newSuffixTrie.contains('bcd')); // true +console.log(newSuffixTrie.contains('cd')); // true +console.log(newSuffixTrie.contains('d')); // true diff --git a/javaScript/medium/threeNumberSum.js b/javaScript/medium/threeNumberSum.js new file mode 100644 index 0000000..8fe10c3 --- /dev/null +++ b/javaScript/medium/threeNumberSum.js @@ -0,0 +1,23 @@ +// O(n^2) time | O(n) space +function threeNumberSum(array, targetSum) { + array.sort((a, b) => a - b); + const triplets = []; + const len = array.length; + for (let i = 0; i <= len - 3; i++) { + let left = i + 1; + let right = len - 1; + while (left < right) { + const currSum = array[i] + array[left] + array[right]; + if (currSum === targetSum) { + triplets.push([array[i], array[left], array[right]]); + left++; + right--; + } else if (currSum > targetSum) { + right--; + } else if (currSum < targetSum) { + left++; + } + } + } + return triplets; +} diff --git a/javaScript/very-hard/calendarMatching.js b/javaScript/very-hard/calendarMatching.js new file mode 100644 index 0000000..3e335a8 --- /dev/null +++ b/javaScript/very-hard/calendarMatching.js @@ -0,0 +1,118 @@ +// calendar1 = [['9:00', '10:30'], ['12:00', '13:00'], ['16:00', '18:00']] +// dailyBounds1 = ['9:00', '20:00']; +// calendar2 = [['10:00', '11:30'], ['12:30', '14:30'], ['14:30', '15:00'], ['16:00', '17:00']] +// dailyBounds2 = ['10:00', '18:30']; +// meetingDuration = 30; + +// Sample Output = = ['10:00', '18:30']; + +// O(c1 + c2) time | O(c1 + c2) space - where c1 and c2 are the respective numbers of meetings +// in calendar 1 and calendar2 + +function calendarMatching( + calendar1, + dailyBounds1, + calendar2, + dailyBounds2, + meetingDuration +) { + const updatedCalendar1 = updateCalendar(calendar1, dailyBounds1); + const updatedCalendar2 = updateCalendar(calendar2, dailyBounds2); + const mergedCalendar = mergeCalendars(updatedCalendar1, updatedCalendar2); + const flattenedCalendar = flattenCalendar(mergedCalendar); + return getMatchingAvailabilities(flattenedCalendar, meetingDuration); +} + +function getMatchingAvailabilities(flattenCalendar, meetingDuration) { + // flattenedCalendar = [[0, 120], [120, 180], [250, 300]]; + let availabilities = []; + + for (let i = 1; i < flattenCalendar.length; i++) { + const previousFinish = flattenCalendar[i - 1][1]; + const currentStart = flattenCalendar[i][0]; + + if (currentStart - previousFinish >= meetingDuration) { + availabilities.push([previousFinish, currentStart]); + } + } + + return availabilities.map((a) => a.map((minutes) => minutesToTime(minutes))); +} + +function flattenCalendar(calendar) { + // Merged calendar = [[0, 120], [10, 90], [80, 120], [150, 200]] + let flattened = [calendar[0]]; + + for (let i = 1; i < calendar.length; i++) { + const previousMeeting = flattened[flattened.length - 1]; + const currentMeeting = calendar[i]; + const [previousStart, previousFinish] = previousMeeting; + const [currentStart, currentFinish] = currentMeeting; + + if (previousFinish >= currentStart) { + flattened[flattened.length - 1] = [ + previousStart, + Math.max(currentFinish, previousFinish), + ]; + } else { + flattened.push(currentMeeting); + } + } + + return flattened; +} + +function mergeCalendars(calendar1, calendar2) { + let merged = []; + let i = 0; + let j = 0; + + while (i < calendar1.length && j < calendar2.length) { + const meeting1 = calendar1[i]; + const meeting2 = calendar2[j]; + + if (meeting1[0] < meeting2[0]) { + merged.push(meeting1); + i++; + } else { + merged.push(meeting2); + j++; + } + } + + while (i < calendar1.length) { + merged.push(calendar1[i]); + i++; + } + while (j < calendar2.length) { + merged.push(calendar2[j]); + j++; + } + + return merged; +} + +function updateCalendar(calendar, dailyBounds) { + const updatedCalendar = [ + ['0:00', dailyBounds[0]], + ...calendar, + [dailyBounds[1], '23:59'], + ]; + return updatedCalendar.map((cal) => cal.map((time) => timeToMinutes(time))); +} + +function timeToMinutes(time) { + const [hour, min] = time.split(':').map((s) => parseInt(s)); + return hour * 60 + min; +} + +function minutesToTime(minutes) { + const hour = Math.floor(minutes / 60); + const min = minutes % 60; + + const minString = min < 10 ? '0' + min : min.toString(); + + return hour + ':' + minString; +} +// Do not edit the line below. +exports.calendarMatching = calendarMatching;