├── 0009-palindrome-number ├── 0009-palindrome-number.js ├── NOTES.md └── README.md ├── 0011-container-with-most-water ├── 0011-container-with-most-water.js ├── NOTES.md └── README.md ├── 0020-valid-parentheses ├── 0020-valid-parentheses.js ├── NOTES.md └── README.md ├── 0049-group-anagrams ├── 0049-group-anagrams.js ├── NOTES.md └── README.md ├── 0098-validate-binary-search-tree ├── 0098-validate-binary-search-tree.js ├── NOTES.md └── README.md ├── 0102-binary-tree-level-order-traversal ├── 0102-binary-tree-level-order-traversal.js ├── NOTES.md └── README.md ├── 0104-maximum-depth-of-binary-tree ├── 0104-maximum-depth-of-binary-tree.js ├── NOTES.md └── README.md ├── 0125-valid-palindrome ├── NOTES.md └── README.md ├── 0141-linked-list-cycle ├── 0141-linked-list-cycle.js ├── NOTES.md └── README.md ├── 0142-linked-list-cycle-ii ├── 0142-linked-list-cycle-ii.js ├── NOTES.md └── README.md ├── 0205-isomorphic-strings ├── 0205-isomorphic-strings.js ├── NOTES.md └── README.md ├── 0206-reverse-linked-list ├── 0206-reverse-linked-list.js └── README.md ├── 0215-kth-largest-element-in-an-array ├── 0215-kth-largest-element-in-an-array.js ├── NOTES.md └── README.md ├── 0217-contains-duplicate ├── 0217-contains-duplicate.js ├── NOTES.md └── README.md ├── 0222-count-complete-tree-nodes ├── 0222-count-complete-tree-nodes.js ├── NOTES.md └── README.md ├── 0242-valid-anagram ├── 0242-valid-anagram.js ├── NOTES.md └── README.md ├── 0263-ugly-number ├── 0263-ugly-number.js ├── NOTES.md └── README.md ├── 0287-find-the-duplicate-number ├── 0287-find-the-duplicate-number.js ├── NOTES.md └── README.md ├── 0344-reverse-string ├── 0344-reverse-string.js ├── NOTES.md └── README.md ├── 0392-is-subsequence ├── 0392-is-subsequence.js ├── NOTES.md └── README.md ├── 0412-fizz-buzz ├── 0412-fizz-buzz.js ├── NOTES.md └── README.md ├── 0430-flatten-a-multilevel-doubly-linked-list ├── 0430-flatten-a-multilevel-doubly-linked-list.js ├── NOTES.md └── README.md ├── 0442-find-all-duplicates-in-an-array ├── 0442-find-all-duplicates-in-an-array.js ├── NOTES.md └── README.md ├── 0509-fibonacci-number ├── 0509-fibonacci-number.js ├── NOTES.md └── README.md ├── 0557-reverse-words-in-a-string-iii ├── 0557-reverse-words-in-a-string-iii.js ├── NOTES.md └── README.md ├── 0709-to-lower-case ├── 0709-to-lower-case.js └── NOTES.md ├── 0724-find-pivot-index ├── 0724-find-pivot-index.js ├── NOTES.md └── README.md ├── 0905-sort-array-by-parity ├── 0905-sort-array-by-parity.js ├── NOTES.md └── README.md ├── 0922-sort-array-by-parity-ii ├── 0922-sort-array-by-parity-ii.js ├── NOTES.md └── README.md ├── 0961-n-repeated-element-in-size-2n-array ├── 0961-n-repeated-element-in-size-2n-array.js └── NOTES.md ├── 1108-defanging-an-ip-address ├── 1108-defanging-an-ip-address.js ├── NOTES.md └── README.md ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer.js └── NOTES.md ├── 1295-find-numbers-with-even-number-of-digits ├── 1295-find-numbers-with-even-number-of-digits.js ├── NOTES.md └── README.md ├── 1342-number-of-steps-to-reduce-a-number-to-zero ├── 1342-number-of-steps-to-reduce-a-number-to-zero.js ├── NOTES.md └── README.md ├── 1365-how-many-numbers-are-smaller-than-the-current-number ├── 1365-how-many-numbers-are-smaller-than-the-current-number.js ├── NOTES.md └── README.md ├── 1389-create-target-array-in-the-given-order ├── 1389-create-target-array-in-the-given-order.js └── README.md ├── 1480-running-sum-of-1d-array ├── 1480-running-sum-of-1d-array.js ├── NOTES.md └── README.md ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary.js ├── NOTES.md └── README.md ├── 1512-number-of-good-pairs ├── 1512-number-of-good-pairs.js ├── NOTES.md └── README.md ├── 1528-shuffle-string ├── 1528-shuffle-string.js ├── NOTES.md └── README.md ├── 1662-check-if-two-string-arrays-are-equivalent ├── 1662-check-if-two-string-arrays-are-equivalent.js ├── NOTES.md └── README.md ├── 1688-count-of-matches-in-tournament ├── 1688-count-of-matches-in-tournament.js ├── NOTES.md └── README.md ├── 1704-determine-if-string-halves-are-alike ├── 1704-determine-if-string-halves-are-alike.js ├── NOTES.md └── README.md ├── 1748-sum-of-unique-elements ├── 1748-sum-of-unique-elements.js ├── NOTES.md └── README.md ├── 1768-merge-strings-alternately ├── 1768-merge-strings-alternately.js ├── NOTES.md └── README.md ├── 1816-truncate-sentence ├── 1816-truncate-sentence.js ├── NOTES.md └── README.md ├── 1832-check-if-the-sentence-is-pangram ├── 1832-check-if-the-sentence-is-pangram.js ├── NOTES.md └── README.md ├── 1859-sorting-the-sentence ├── 1859-sorting-the-sentence.js ├── NOTES.md └── README.md ├── 1880-check-if-word-equals-summation-of-two-words ├── 1880-check-if-word-equals-summation-of-two-words.js ├── NOTES.md └── README.md ├── 1920-build-array-from-permutation ├── 1920-build-array-from-permutation.js ├── NOTES.md └── README.md ├── 1941-check-if-all-characters-have-equal-number-of-occurrences ├── 1941-check-if-all-characters-have-equal-number-of-occurrences.js ├── NOTES.md └── README.md ├── 2000-reverse-prefix-of-word ├── 2000-reverse-prefix-of-word.js ├── NOTES.md └── README.md ├── 2006-count-number-of-pairs-with-absolute-difference-k ├── 2006-count-number-of-pairs-with-absolute-difference-k.js ├── NOTES.md └── README.md ├── 2032-two-out-of-three ├── 2032-two-out-of-three.js ├── NOTES.md └── README.md ├── 2108-find-first-palindromic-string-in-the-array ├── 2108-find-first-palindromic-string-in-the-array.js ├── NOTES.md └── README.md ├── 2149-rearrange-array-elements-by-sign ├── 2149-rearrange-array-elements-by-sign.js ├── NOTES.md └── README.md ├── 2161-partition-array-according-to-given-pivot ├── 2161-partition-array-according-to-given-pivot.js ├── NOTES.md └── README.md ├── 2169-count-operations-to-obtain-zero ├── 2169-count-operations-to-obtain-zero.js ├── NOTES.md └── README.md ├── 2235-add-two-integers ├── 2235-add-two-integers.js ├── NOTES.md └── README.md ├── 2351-first-letter-to-appear-twice ├── 2351-first-letter-to-appear-twice.js ├── NOTES.md └── README.md ├── 2396-strictly-palindromic-number ├── 2396-strictly-palindromic-number.js ├── NOTES.md └── README.md ├── 2413-smallest-even-multiple ├── 2413-smallest-even-multiple.js ├── NOTES.md └── README.md ├── 2418-sort-the-people ├── 2418-sort-the-people.js ├── NOTES.md └── README.md ├── 2427-number-of-common-factors ├── 2427-number-of-common-factors.js └── NOTES.md ├── 2442-count-number-of-distinct-integers-after-reverse-operations ├── 2442-count-number-of-distinct-integers-after-reverse-operations.js ├── NOTES.md └── README.md ├── 2469-convert-the-temperature ├── 2469-convert-the-temperature.js ├── NOTES.md └── README.md ├── 2500-delete-greatest-value-in-each-row ├── 2500-delete-greatest-value-in-each-row.js ├── NOTES.md └── README.md ├── 2520-count-the-digits-that-divide-a-number ├── 2520-count-the-digits-that-divide-a-number.js ├── NOTES.md └── README.md ├── 2529-maximum-count-of-positive-integer-and-negative-integer ├── 2529-maximum-count-of-positive-integer-and-negative-integer.js └── README.md ├── 2535-difference-between-element-sum-and-digit-sum-of-an-array ├── 2535-difference-between-element-sum-and-digit-sum-of-an-array.js ├── NOTES.md └── README.md ├── 2544-alternating-digit-sum ├── 2544-alternating-digit-sum.js ├── NOTES.md └── README.md ├── 2553-separate-the-digits-in-an-array ├── 2553-separate-the-digits-in-an-array.js ├── NOTES.md └── README.md ├── 2574-left-and-right-sum-differences ├── 2574-left-and-right-sum-differences.js ├── NOTES.md └── README.md ├── README.md ├── duplicate-zeros ├── README.md └── duplicate-zeros.js ├── find-numbers-with-even-number-of-digits ├── README.md └── find-numbers-with-even-number-of-digits.js └── squares-of-a-sorted-array ├── README.md └── squares-of-a-sorted-array.js /0009-palindrome-number/0009-palindrome-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} x 3 | * @return {boolean} 4 | */ 5 | var isPalindrome = function(x) { 6 | x = String(x); 7 | x = x.split(""); 8 | let l = 0; 9 | let r = x.length -1; 10 | 11 | while(l 9. Palindrome Number

Easy


Given an integer x, return true if x is a palindrome, and false otherwise.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: x = 121
 7 | Output: true
 8 | Explanation: 121 reads as 121 from left to right and from right to left.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: x = -121
14 | Output: false
15 | Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
16 | 
17 | 18 |

Example 3:

19 | 20 |
Input: x = 10
21 | Output: false
22 | Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 | 31 | 32 |

 

33 | Follow up: Could you solve it without converting the integer to a string?
-------------------------------------------------------------------------------- /0011-container-with-most-water/0011-container-with-most-water.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} height 3 | * @return {number} 4 | */ 5 | var maxArea = function(height) { 6 | let mymaxArea = 0; 7 | let s = 0; 8 | let e = height.length -1; 9 | while( s < e){ 10 | let l = Math.min(height[s], height[e]); 11 | let w = e - s; 12 | let a = l * w; 13 | mymaxArea = Math.max(a,mymaxArea); 14 | if(height[s] <= height[e]){ 15 | s++; 16 | }else{ 17 | e--; 18 | } 19 | } 20 | return mymaxArea; 21 | 22 | }; -------------------------------------------------------------------------------- /0011-container-with-most-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0011-container-with-most-water/README.md: -------------------------------------------------------------------------------- 1 |

11. Container With Most Water

Medium


You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

2 | 3 |

Find two lines that together with the x-axis form a container, such that the container contains the most water.

4 | 5 |

Return the maximum amount of water a container can store.

6 | 7 |

Notice that you may not slant the container.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: height = [1,8,6,2,5,4,8,3,7]
13 | Output: 49
14 | Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: height = [1,1]
20 | Output: 1
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 | 31 |
-------------------------------------------------------------------------------- /0020-valid-parentheses/0020-valid-parentheses.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {boolean} 4 | */ 5 | var isValid = function(s) { 6 | let paren = { 7 | '(':')', 8 | '{':'}', 9 | '[':']', 10 | } 11 | let stk = []; 12 | for(let i=0; i20. Valid Parentheses

Easy


Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

2 | 3 |

An input string is valid if:

4 | 5 |
    6 |
  1. Open brackets must be closed by the same type of brackets.
  2. 7 |
  3. Open brackets must be closed in the correct order.
  4. 8 |
  5. Every close bracket has a corresponding open bracket of the same type.
  6. 9 |
10 | 11 |

 

12 |

Example 1:

13 | 14 |
Input: s = "()"
15 | Output: true
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: s = "()[]{}"
21 | Output: true
22 | 
23 | 24 |

Example 3:

25 | 26 |
Input: s = "(]"
27 | Output: false
28 | 
29 | 30 |

 

31 |

Constraints:

32 | 33 |
    34 |
  • 1 <= s.length <= 104
  • 35 |
  • s consists of parentheses only '()[]{}'.
  • 36 |
37 |
-------------------------------------------------------------------------------- /0049-group-anagrams/0049-group-anagrams.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} strs 3 | * @return {string[][]} 4 | */ 5 | var groupAnagrams = function(strs) { 6 | let sorted = []; 7 | for(let i=0; i49. Group Anagrams

Medium


Given an array of strings strs, group the anagrams together. You can return the answer in any order.

2 | 3 |

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

4 | 5 |

 

6 |

Example 1:

7 |
Input: strs = ["eat","tea","tan","ate","nat","bat"]
 8 | Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
 9 | 

Example 2:

10 |
Input: strs = [""]
11 | Output: [[""]]
12 | 

Example 3:

13 |
Input: strs = ["a"]
14 | Output: [["a"]]
15 | 
16 |

 

17 |

Constraints:

18 | 19 |
    20 |
  • 1 <= strs.length <= 104
  • 21 |
  • 0 <= strs[i].length <= 100
  • 22 |
  • strs[i] consists of lowercase English letters.
  • 23 |
24 |
-------------------------------------------------------------------------------- /0098-validate-binary-search-tree/0098-validate-binary-search-tree.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {boolean} 12 | */ 13 | const dfs = function(node, min, max) { 14 | if(node.val <= min || node.val >= max) { 15 | return false; 16 | } 17 | 18 | if(node.left) { 19 | if(!dfs(node.left, min, node.val)){ 20 | return false; 21 | }; 22 | } 23 | 24 | if(node.right) { 25 | if(!dfs(node.right, node.val, max)) { 26 | return false; 27 | } 28 | } 29 | 30 | return true; 31 | } 32 | 33 | const isValidBST = function(root) { 34 | if(!root) return true; 35 | return dfs(root, -Infinity, Infinity); 36 | }; -------------------------------------------------------------------------------- /0098-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0098-validate-binary-search-tree/README.md: -------------------------------------------------------------------------------- 1 |

98. Validate Binary Search Tree

Medium


Given the root of a binary tree, determine if it is a valid binary search tree (BST).

2 | 3 |

A valid BST is defined as follows:

4 | 5 |
    6 |
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • 7 |
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • 8 |
  • Both the left and right subtrees must also be binary search trees.
  • 9 |
10 | 11 |

 

12 |

Example 1:

13 | 14 |
Input: root = [2,1,3]
15 | Output: true
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: root = [5,1,4,null,null,3,6]
21 | Output: false
22 | Explanation: The root node's value is 5 but its right child's value is 4.
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 |
    29 |
  • The number of nodes in the tree is in the range [1, 104].
  • 30 |
  • -231 <= Node.val <= 231 - 1
  • 31 |
32 |
-------------------------------------------------------------------------------- /0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number[][]} 12 | */ 13 | var levelOrder = function(root) { 14 | if(!root) return []; 15 | let res = []; 16 | let queue = [root]; 17 | while(queue.length) 18 | { 19 | let len = queue.length; 20 | let count = 0; 21 | let currentvalue = []; 22 | while(count < len) 23 | { 24 | let node = queue.shift(); 25 | currentvalue.push(node.val); 26 | if(node.left) queue.push(node.left); 27 | if(node.right) queue.push(node.right); 28 | count++; 29 | } 30 | res.push(currentvalue); 31 | } 32 | return res; 33 | }; -------------------------------------------------------------------------------- /0102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0102-binary-tree-level-order-traversal/README.md: -------------------------------------------------------------------------------- 1 |

102. Binary Tree Level Order Traversal

Medium


Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: root = [3,9,20,null,null,15,7]
 7 | Output: [[3],[9,20],[15,7]]
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: root = [1]
13 | Output: [[1]]
14 | 
15 | 16 |

Example 3:

17 | 18 |
Input: root = []
19 | Output: []
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • The number of nodes in the tree is in the range [0, 2000].
  • 27 |
  • -1000 <= Node.val <= 1000
  • 28 |
29 |
-------------------------------------------------------------------------------- /0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number} 12 | */ 13 | var maxDepth = function(root) { 14 | if(!root) 15 | { 16 | return 0; 17 | } 18 | return 1 + Math.max(maxDepth(root.right), maxDepth(root.left)); 19 | 20 | }; -------------------------------------------------------------------------------- /0104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0104-maximum-depth-of-binary-tree/README.md: -------------------------------------------------------------------------------- 1 |

104. Maximum Depth of Binary Tree

Easy


Given the root of a binary tree, return its maximum depth.

2 | 3 |

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: root = [3,9,20,null,null,15,7]
 9 | Output: 3
10 | 
11 | 12 |

Example 2:

13 | 14 |
Input: root = [1,null,2]
15 | Output: 2
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • The number of nodes in the tree is in the range [0, 104].
  • 23 |
  • -100 <= Node.val <= 100
  • 24 |
25 |
-------------------------------------------------------------------------------- /0125-valid-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0125-valid-palindrome/README.md: -------------------------------------------------------------------------------- 1 |

125. Valid Palindrome

Easy


A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.

2 | 3 |

Given a string s, return true if it is a palindrome, or false otherwise.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: s = "A man, a plan, a canal: Panama"
 9 | Output: true
10 | Explanation: "amanaplanacanalpanama" is a palindrome.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: s = "race a car"
16 | Output: false
17 | Explanation: "raceacar" is not a palindrome.
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: s = " "
23 | Output: true
24 | Explanation: s is an empty string "" after removing non-alphanumeric characters.
25 | Since an empty string reads the same forward and backward, it is a palindrome.
26 | 
27 | 28 |

 

29 |

Constraints:

30 | 31 |
    32 |
  • 1 <= s.length <= 2 * 105
  • 33 |
  • s consists only of printable ASCII characters.
  • 34 |
35 |
-------------------------------------------------------------------------------- /0141-linked-list-cycle/0141-linked-list-cycle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * function ListNode(val) { 4 | * this.val = val; 5 | * this.next = null; 6 | * } 7 | */ 8 | 9 | /** 10 | * @param {ListNode} head 11 | * @return {boolean} 12 | */ 13 | var hasCycle = function(head) { 14 | if(head ==null) return false; 15 | let hare = head 16 | let tortoise = head; 17 | 18 | while(true) 19 | { 20 | hare = hare.next; 21 | tortoise = tortoise.next; 22 | if(hare == null || hare.next == null) 23 | { 24 | return false; 25 | }else{ 26 | hare = hare.next; 27 | } 28 | if(hare == tortoise) break;; 29 | 30 | } 31 | return true; 32 | }; -------------------------------------------------------------------------------- /0141-linked-list-cycle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0141-linked-list-cycle/README.md: -------------------------------------------------------------------------------- 1 |

141. Linked List Cycle

Easy


Given head, the head of a linked list, determine if the linked list has a cycle in it.

2 | 3 |

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

4 | 5 |

Return true if there is a cycle in the linked list. Otherwise, return false.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: head = [3,2,0,-4], pos = 1
11 | Output: true
12 | Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).
13 | 
14 | 15 |

Example 2:

16 | 17 |
Input: head = [1,2], pos = 0
18 | Output: true
19 | Explanation: There is a cycle in the linked list, where the tail connects to the 0th node.
20 | 
21 | 22 |

Example 3:

23 | 24 |
Input: head = [1], pos = -1
25 | Output: false
26 | Explanation: There is no cycle in the linked list.
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • The number of the nodes in the list is in the range [0, 104].
  • 34 |
  • -105 <= Node.val <= 105
  • 35 |
  • pos is -1 or a valid index in the linked-list.
  • 36 |
37 | 38 |

 

39 |

Follow up: Can you solve it using O(1) (i.e. constant) memory?

40 |
-------------------------------------------------------------------------------- /0142-linked-list-cycle-ii/0142-linked-list-cycle-ii.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * function ListNode(val) { 4 | * this.val = val; 5 | * this.next = null; 6 | * } 7 | */ 8 | 9 | /** 10 | * @param {ListNode} head 11 | * @return {ListNode} 12 | */ 13 | var detectCycle = function(head) { 14 | if(head == null) return null; 15 | let f = head; 16 | let s = head; 17 | while(true) 18 | { 19 | f = f.next; 20 | s = s.next; 21 | if(f ==null || f.next == null){ 22 | return null; 23 | }else{ 24 | f = f.next; 25 | } 26 | if(f == s) break; 27 | } 28 | let p1 = head; 29 | let p2 = s; 30 | while(p1 !== p2) 31 | { 32 | p1 = p1.next; 33 | p2 = p2.next; 34 | } 35 | return p1; 36 | 37 | }; -------------------------------------------------------------------------------- /0142-linked-list-cycle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0142-linked-list-cycle-ii/README.md: -------------------------------------------------------------------------------- 1 |

142. Linked List Cycle II

Medium


Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

2 | 3 |

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note that pos is not passed as a parameter.

4 | 5 |

Do not modify the linked list.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: head = [3,2,0,-4], pos = 1
11 | Output: tail connects to node index 1
12 | Explanation: There is a cycle in the linked list, where tail connects to the second node.
13 | 
14 | 15 |

Example 2:

16 | 17 |
Input: head = [1,2], pos = 0
18 | Output: tail connects to node index 0
19 | Explanation: There is a cycle in the linked list, where tail connects to the first node.
20 | 
21 | 22 |

Example 3:

23 | 24 |
Input: head = [1], pos = -1
25 | Output: no cycle
26 | Explanation: There is no cycle in the linked list.
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • The number of the nodes in the list is in the range [0, 104].
  • 34 |
  • -105 <= Node.val <= 105
  • 35 |
  • pos is -1 or a valid index in the linked-list.
  • 36 |
37 | 38 |

 

39 |

Follow up: Can you solve it using O(1) (i.e. constant) memory?

40 |
-------------------------------------------------------------------------------- /0205-isomorphic-strings/0205-isomorphic-strings.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isIsomorphic = function(s, t) { 7 | 8 | for(let i=0; i205. Isomorphic Strings

Easy


Given two strings s and t, determine if they are isomorphic.

2 | 3 |

Two strings s and t are isomorphic if the characters in s can be replaced to get t.

4 | 5 |

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

6 | 7 |

 

8 |

Example 1:

9 |
Input: s = "egg", t = "add"
10 | Output: true
11 | 

Example 2:

12 |
Input: s = "foo", t = "bar"
13 | Output: false
14 | 

Example 3:

15 |
Input: s = "paper", t = "title"
16 | Output: true
17 | 
18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • 1 <= s.length <= 5 * 104
  • 23 |
  • t.length == s.length
  • 24 |
  • s and t consist of any valid ascii character.
  • 25 |
26 |
-------------------------------------------------------------------------------- /0206-reverse-linked-list/0206-reverse-linked-list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * function ListNode(val, next) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.next = (next===undefined ? null : next) 6 | * } 7 | */ 8 | /** 9 | * @param {ListNode} head 10 | * @return {ListNode} 11 | */ 12 | var reverseList = function(head) { 13 | let store = null; 14 | let current = head; 15 | while(current) 16 | { 17 | let next = current.next; 18 | current.next = store; 19 | store = current; 20 | current = next; 21 | } 22 | return store 23 | }; -------------------------------------------------------------------------------- /0206-reverse-linked-list/README.md: -------------------------------------------------------------------------------- 1 |

206. Reverse Linked List

Easy


Given the head of a singly linked list, reverse the list, and return the reversed list.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: head = [1,2,3,4,5]
 7 | Output: [5,4,3,2,1]
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: head = [1,2]
13 | Output: [2,1]
14 | 
15 | 16 |

Example 3:

17 | 18 |
Input: head = []
19 | Output: []
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • The number of nodes in the list is the range [0, 5000].
  • 27 |
  • -5000 <= Node.val <= 5000
  • 28 |
29 | 30 |

 

31 |

Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?

32 |
-------------------------------------------------------------------------------- /0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | var findKthLargest = function(nums, k) { 7 | let indexToFind = nums.length -k; 8 | quick(nums, 0, nums.length -1); 9 | return nums[indexToFind]; 10 | 11 | }; 12 | 13 | 14 | let quick = (arr, left, right)=>{ 15 | if(left < right) 16 | { 17 | let partitionIndex = Partition(arr, left, right); 18 | quick(arr, left, partitionIndex -1); 19 | quick(arr, partitionIndex +1, right); 20 | } 21 | 22 | } 23 | 24 | 25 | let Partition = (arr,left,right)=>{ 26 | 27 | let piviot = arr[right]; 28 | let i = left; 29 | for(let j=left; j{ 42 | let temp = arr[i]; 43 | arr[i] = arr[j]; 44 | arr[j] = temp; 45 | } -------------------------------------------------------------------------------- /0215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0215-kth-largest-element-in-an-array/README.md: -------------------------------------------------------------------------------- 1 |

215. Kth Largest Element in an Array

Medium


Given an integer array nums and an integer k, return the kth largest element in the array.

2 | 3 |

Note that it is the kth largest element in the sorted order, not the kth distinct element.

4 | 5 |

You must solve it in O(n) time complexity.

6 | 7 |

 

8 |

Example 1:

9 |
Input: nums = [3,2,1,5,6,4], k = 2
10 | Output: 5
11 | 

Example 2:

12 |
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
13 | Output: 4
14 | 
15 |

 

16 |

Constraints:

17 | 18 |
    19 |
  • 1 <= k <= nums.length <= 105
  • 20 |
  • -104 <= nums[i] <= 104
  • 21 |
22 |
-------------------------------------------------------------------------------- /0217-contains-duplicate/0217-contains-duplicate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {boolean} 4 | */ 5 | var containsDuplicate = function(nums) { 6 | let obj = {}; 7 | for( n of nums) 8 | { 9 | if(obj[n]) 10 | { 11 | return true; 12 | } 13 | else{ 14 | obj[n] = 1; 15 | } 16 | } 17 | return false; 18 | }; -------------------------------------------------------------------------------- /0217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0217-contains-duplicate/README.md: -------------------------------------------------------------------------------- 1 |

217. Contains Duplicate

Easy


Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

2 | 3 |

 

4 |

Example 1:

5 |
Input: nums = [1,2,3,1]
 6 | Output: true
 7 | 

Example 2:

8 |
Input: nums = [1,2,3,4]
 9 | Output: false
10 | 

Example 3:

11 |
Input: nums = [1,1,1,3,3,4,3,2,4,2]
12 | Output: true
13 | 
14 |

 

15 |

Constraints:

16 | 17 |
    18 |
  • 1 <= nums.length <= 105
  • 19 |
  • -109 <= nums[i] <= 109
  • 20 |
21 |
-------------------------------------------------------------------------------- /0222-count-complete-tree-nodes/0222-count-complete-tree-nodes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * function TreeNode(val, left, right) { 4 | * this.val = (val===undefined ? 0 : val) 5 | * this.left = (left===undefined ? null : left) 6 | * this.right = (right===undefined ? null : right) 7 | * } 8 | */ 9 | /** 10 | * @param {TreeNode} root 11 | * @return {number} 12 | */ 13 | var countNodes = function(root) { 14 | const getTreeHeight = function(root) { 15 | let height = 0; 16 | while(root.left !== null) { 17 | height++; 18 | root = root.left; 19 | } 20 | 21 | return height; 22 | } 23 | 24 | const nodeExists = function(idxToFind, height, node) { 25 | let left = 0, right = Math.pow(2, height) - 1, count = 0; 26 | 27 | while(count < height) { 28 | const midOfNode = Math.ceil((left + right) / 2); 29 | 30 | if(idxToFind >= midOfNode) { 31 | node = node.right; 32 | left = midOfNode; 33 | } else { 34 | node = node.left; 35 | right = midOfNode - 1; 36 | } 37 | 38 | count++; 39 | } 40 | 41 | return node !== null; 42 | } 43 | if(!root) return 0; 44 | 45 | const height = getTreeHeight(root); 46 | 47 | if(height === 0) return 1; 48 | 49 | const upperCount = Math.pow(2, height) - 1 50 | 51 | let left = 0, right = upperCount; 52 | 53 | while(left < right) { 54 | const idxToFind = Math.ceil((left + right) / 2); 55 | 56 | if(nodeExists(idxToFind, height, root)) { 57 | left = idxToFind; 58 | } else { 59 | right = idxToFind - 1; 60 | } 61 | } 62 | 63 | return upperCount + left + 1; 64 | }; -------------------------------------------------------------------------------- /0222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0222-count-complete-tree-nodes/README.md: -------------------------------------------------------------------------------- 1 |

222. Count Complete Tree Nodes

Medium


Given the root of a complete binary tree, return the number of the nodes in the tree.

2 | 3 |

According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

4 | 5 |

Design an algorithm that runs in less than O(n) time complexity.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: root = [1,2,3,4,5,6]
11 | Output: 6
12 | 
13 | 14 |

Example 2:

15 | 16 |
Input: root = []
17 | Output: 0
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: root = [1]
23 | Output: 1
24 | 
25 | 26 |

 

27 |

Constraints:

28 | 29 |
    30 |
  • The number of nodes in the tree is in the range [0, 5 * 104].
  • 31 |
  • 0 <= Node.val <= 5 * 104
  • 32 |
  • The tree is guaranteed to be complete.
  • 33 |
34 |
-------------------------------------------------------------------------------- /0242-valid-anagram/0242-valid-anagram.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isAnagram = function(s, t) { 7 | s = s.split("").sort(); 8 | t = t.split("").sort(); 9 | 10 | if(s.length !== t.length) return false; 11 | 12 | for(let i=0; i242. Valid Anagram

Easy


Given two strings s and t, return true if t is an anagram of s, and false otherwise.

2 | 3 |

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "anagram", t = "nagaram"
 8 | Output: true
 9 | 

Example 2:

10 |
Input: s = "rat", t = "car"
11 | Output: false
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= s.length, t.length <= 5 * 104
  • 18 |
  • s and t consist of lowercase English letters.
  • 19 |
20 | 21 |

 

22 |

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

23 |
-------------------------------------------------------------------------------- /0263-ugly-number/0263-ugly-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | var isUgly = function(n) { 6 | if(n<=0) return false; 7 | 8 | while(n!==1) 9 | { 10 | if(n%2==0) 11 | { 12 | n = n/2; 13 | } 14 | else if(n%3==0) 15 | { 16 | n = n/3; 17 | } 18 | else if(n%5==0) 19 | { 20 | n = n/5; 21 | } 22 | else{ 23 | return false; 24 | } 25 | } 26 | return true; 27 | 28 | }; -------------------------------------------------------------------------------- /0263-ugly-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0263-ugly-number/README.md: -------------------------------------------------------------------------------- 1 |

263. Ugly Number

Easy


An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

2 | 3 |

Given an integer n, return true if n is an ugly number.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: n = 6
 9 | Output: true
10 | Explanation: 6 = 2 × 3
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: n = 1
16 | Output: true
17 | Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: n = 14
23 | Output: false
24 | Explanation: 14 is not ugly since it includes the prime factor 7.
25 | 
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • -231 <= n <= 231 - 1
  • 32 |
33 |
-------------------------------------------------------------------------------- /0287-find-the-duplicate-number/0287-find-the-duplicate-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var findDuplicate = function(nums) { 6 | let obj = {}; 7 | for(n of nums) 8 | { 9 | if(obj[n]) 10 | { 11 | return n; 12 | } 13 | else{ 14 | obj[n] = 1 15 | } 16 | 17 | } 18 | }; -------------------------------------------------------------------------------- /0287-find-the-duplicate-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0287-find-the-duplicate-number/README.md: -------------------------------------------------------------------------------- 1 |

287. Find the Duplicate Number

Medium


Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

2 | 3 |

There is only one repeated number in nums, return this repeated number.

4 | 5 |

You must solve the problem without modifying the array nums and uses only constant extra space.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: nums = [1,3,4,2,2]
11 | Output: 2
12 | 
13 | 14 |

Example 2:

15 | 16 |
Input: nums = [3,1,3,4,2]
17 | Output: 3
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= n <= 105
  • 25 |
  • nums.length == n + 1
  • 26 |
  • 1 <= nums[i] <= n
  • 27 |
  • All the integers in nums appear only once except for precisely one integer which appears two or more times.
  • 28 |
29 | 30 |

 

31 |

Follow up:

32 | 33 |
    34 |
  • How can we prove that at least one duplicate number must exist in nums?
  • 35 |
  • Can you solve the problem in linear runtime complexity?
  • 36 |
37 |
-------------------------------------------------------------------------------- /0344-reverse-string/0344-reverse-string.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {character[]} s 3 | * @return {void} Do not return anything, modify s in-place instead. 4 | */ 5 | var reverseString = function(s) { 6 | let l = 0; 7 | let r = s.length -1; 8 | while(l344. Reverse String

Easy


Write a function that reverses a string. The input string is given as an array of characters s.

2 | 3 |

You must do this by modifying the input array in-place with O(1) extra memory.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = ["h","e","l","l","o"]
 8 | Output: ["o","l","l","e","h"]
 9 | 

Example 2:

10 |
Input: s = ["H","a","n","n","a","h"]
11 | Output: ["h","a","n","n","a","H"]
12 | 
13 |

 

14 |

Constraints:

15 | 16 | 20 |
-------------------------------------------------------------------------------- /0392-is-subsequence/0392-is-subsequence.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {string} t 4 | * @return {boolean} 5 | */ 6 | var isSubsequence = function(s, t) { 7 | let sub = 0; 8 | for(let i=0; i392. Is Subsequence

Easy


Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

2 | 3 |

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "abc", t = "ahbgdc"
 8 | Output: true
 9 | 

Example 2:

10 |
Input: s = "axc", t = "ahbgdc"
11 | Output: false
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 0 <= s.length <= 100
  • 18 |
  • 0 <= t.length <= 104
  • 19 |
  • s and t consist only of lowercase English letters.
  • 20 |
21 | 22 |

 

23 | Follow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?
-------------------------------------------------------------------------------- /0412-fizz-buzz/0412-fizz-buzz.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {string[]} 4 | */ 5 | var fizzBuzz = function(n) { 6 | let res = []; 7 | for(let i=1; i<=n; i++) 8 | { 9 | if(i%3==0 && i%5==0) 10 | { 11 | res.push("FizzBuzz"); 12 | }else if(i%3==0) 13 | { 14 | res.push("Fizz"); 15 | }else if(i%5==0){ 16 | res.push("Buzz"); 17 | } 18 | else{ 19 | res.push(String(i)); 20 | } 21 | 22 | } 23 | return res; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /0412-fizz-buzz/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0412-fizz-buzz/README.md: -------------------------------------------------------------------------------- 1 |

412. Fizz Buzz

Easy


Given an integer n, return a string array answer (1-indexed) where:

2 | 3 |
    4 |
  • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
  • 5 |
  • answer[i] == "Fizz" if i is divisible by 3.
  • 6 |
  • answer[i] == "Buzz" if i is divisible by 5.
  • 7 |
  • answer[i] == i (as a string) if none of the above conditions are true.
  • 8 |
9 | 10 |

 

11 |

Example 1:

12 |
Input: n = 3
13 | Output: ["1","2","Fizz"]
14 | 

Example 2:

15 |
Input: n = 5
16 | Output: ["1","2","Fizz","4","Buzz"]
17 | 

Example 3:

18 |
Input: n = 15
19 | Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
20 | 
21 |

 

22 |

Constraints:

23 | 24 |
    25 |
  • 1 <= n <= 104
  • 26 |
27 |
-------------------------------------------------------------------------------- /0430-flatten-a-multilevel-doubly-linked-list/0430-flatten-a-multilevel-doubly-linked-list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * // Definition for a Node. 3 | * function Node(val,prev,next,child) { 4 | * this.val = val; 5 | * this.prev = prev; 6 | * this.next = next; 7 | * this.child = child; 8 | * }; 9 | */ 10 | 11 | /** 12 | * @param {Node} head 13 | * @return {Node} 14 | */ 15 | var flatten = function(head) { 16 | if (!head) return head; 17 | 18 | let currentNode = head; 19 | while (currentNode !== null) { 20 | if (currentNode.child === null) { 21 | currentNode = currentNode.next; 22 | } else { 23 | let tail = currentNode.child; 24 | while (tail.next !== null) { 25 | tail = tail.next; 26 | } 27 | 28 | tail.next = currentNode.next; 29 | if (tail.next !== null) { 30 | tail.next.prev = tail; 31 | } 32 | 33 | currentNode.next = currentNode.child; 34 | currentNode.next.prev = currentNode; 35 | currentNode.child = null; 36 | } 37 | } 38 | 39 | return head; 40 | 41 | }; -------------------------------------------------------------------------------- /0430-flatten-a-multilevel-doubly-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0430-flatten-a-multilevel-doubly-linked-list/README.md: -------------------------------------------------------------------------------- 1 |

430. Flatten a Multilevel Doubly Linked List

Medium


You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure as shown in the example below.

2 | 3 |

Given the head of the first level of the list, flatten the list so that all the nodes appear in a single-level, doubly linked list. Let curr be a node with a child list. The nodes in the child list should appear after curr and before curr.next in the flattened list.

4 | 5 |

Return the head of the flattened list. The nodes in the list must have all of their child pointers set to null.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
11 | Output: [1,2,3,7,8,11,12,9,10,4,5,6]
12 | Explanation: The multilevel linked list in the input is shown.
13 | After flattening the multilevel linked list it becomes:
14 | 
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: head = [1,2,null,3]
20 | Output: [1,3,2]
21 | Explanation: The multilevel linked list in the input is shown.
22 | After flattening the multilevel linked list it becomes:
23 | 
24 | 
25 | 26 |

Example 3:

27 | 28 |
Input: head = []
29 | Output: []
30 | Explanation: There could be empty list in the input.
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • The number of Nodes will not exceed 1000.
  • 38 |
  • 1 <= Node.val <= 105
  • 39 |
40 | 41 |

 

42 |

How the multilevel linked list is represented in test cases:

43 | 44 |

We use the multilevel linked list from Example 1 above:

45 | 46 |
 1---2---3---4---5---6--NULL
47 |          |
48 |          7---8---9---10--NULL
49 |              |
50 |              11--12--NULL
51 | 52 |

The serialization of each level is as follows:

53 | 54 |
[1,2,3,4,5,6,null]
55 | [7,8,9,10,null]
56 | [11,12,null]
57 | 
58 | 59 |

To serialize all levels together, we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:

60 | 61 |
[1,    2,    3, 4, 5, 6, null]
62 |              |
63 | [null, null, 7,    8, 9, 10, null]
64 |                    |
65 | [            null, 11, 12, null]
66 | 
67 | 68 |

Merging the serialization of each level and removing trailing nulls we obtain:

69 | 70 |
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
71 | 
72 |
-------------------------------------------------------------------------------- /0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var findDuplicates = function(nums) { 6 | let obj = {}; 7 | let res = []; 8 | 9 | for(n of nums) 10 | { 11 | if(obj[n]) 12 | { 13 | res.push(n); 14 | }else 15 | { 16 | obj[n] = 1; 17 | } 18 | } 19 | return res; 20 | }; -------------------------------------------------------------------------------- /0442-find-all-duplicates-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0442-find-all-duplicates-in-an-array/README.md: -------------------------------------------------------------------------------- 1 |

442. Find All Duplicates in an Array

Medium


Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

2 | 3 |

You must write an algorithm that runs in O(n) time and uses only constant extra space.

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [4,3,2,7,8,2,3,1]
 8 | Output: [2,3]
 9 | 

Example 2:

10 |
Input: nums = [1,1,2]
11 | Output: [1]
12 | 

Example 3:

13 |
Input: nums = [1]
14 | Output: []
15 | 
16 |

 

17 |

Constraints:

18 | 19 |
    20 |
  • n == nums.length
  • 21 |
  • 1 <= n <= 105
  • 22 |
  • 1 <= nums[i] <= n
  • 23 |
  • Each element in nums appears once or twice.
  • 24 |
25 |
-------------------------------------------------------------------------------- /0509-fibonacci-number/0509-fibonacci-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var fib = function(n) { 6 | 7 | if(n <2) 8 | { 9 | return n; 10 | } 11 | 12 | return fib(n-1) + fib(n-2); 13 | 14 | }; -------------------------------------------------------------------------------- /0509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0509-fibonacci-number/README.md: -------------------------------------------------------------------------------- 1 |

509. Fibonacci Number

Easy


The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

2 | 3 |
F(0) = 0, F(1) = 1
 4 | F(n) = F(n - 1) + F(n - 2), for n > 1.
 5 | 
6 | 7 |

Given n, calculate F(n).

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: n = 2
13 | Output: 1
14 | Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: n = 3
20 | Output: 2
21 | Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
22 | 
23 | 24 |

Example 3:

25 | 26 |
Input: n = 4
27 | Output: 3
28 | Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • 0 <= n <= 30
  • 36 |
37 |
-------------------------------------------------------------------------------- /0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {string} 4 | */ 5 | var reverseWords = function(s) { 6 | s = s.split(" "); 7 | for(let i=0; i557. Reverse Words in a String III

Easy


Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

2 | 3 |

 

4 |

Example 1:

5 |
Input: s = "Let's take LeetCode contest"
 6 | Output: "s'teL ekat edoCteeL tsetnoc"
 7 | 

Example 2:

8 |
Input: s = "God Ding"
 9 | Output: "doG gniD"
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= s.length <= 5 * 104
  • 16 |
  • s contains printable ASCII characters.
  • 17 |
  • s does not contain any leading or trailing spaces.
  • 18 |
  • There is at least one word in s.
  • 19 |
  • All the words in s are separated by a single space.
  • 20 |
21 |
-------------------------------------------------------------------------------- /0709-to-lower-case/0709-to-lower-case.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {string} 4 | */ 5 | var toLowerCase = function(s) { 6 | 7 | let big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 8 | let small = "abcdefghijklmnopqrstuvwxyz"; 9 | 10 | s = s.split(""); 11 | 12 | 13 | for(let i=0; i724. Find Pivot Index

Easy


Given an array of integers nums, calculate the pivot index of this array.

2 | 3 |

The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.

4 | 5 |

If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.

6 | 7 |

Return the leftmost pivot index. If no such index exists, return -1.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: nums = [1,7,3,6,5,6]
13 | Output: 3
14 | Explanation:
15 | The pivot index is 3.
16 | Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11
17 | Right sum = nums[4] + nums[5] = 5 + 6 = 11
18 | 
19 | 20 |

Example 2:

21 | 22 |
Input: nums = [1,2,3]
23 | Output: -1
24 | Explanation:
25 | There is no index that satisfies the conditions in the problem statement.
26 | 27 |

Example 3:

28 | 29 |
Input: nums = [2,1,-1]
30 | Output: 0
31 | Explanation:
32 | The pivot index is 0.
33 | Left sum = 0 (no elements to the left of index 0)
34 | Right sum = nums[1] + nums[2] = 1 + -1 = 0
35 | 
36 | 37 |

 

38 |

Constraints:

39 | 40 |
    41 |
  • 1 <= nums.length <= 104
  • 42 |
  • -1000 <= nums[i] <= 1000
  • 43 |
44 | 45 |

 

46 |

Note: This question is the same as 1991: https://leetcode.com/problems/find-the-middle-index-in-array/

47 |
-------------------------------------------------------------------------------- /0905-sort-array-by-parity/0905-sort-array-by-parity.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var sortArrayByParity = function(nums) { 6 | 7 | let even = []; 8 | let odd = []; 9 | let res = []; 10 | 11 | for(let i=0; i905. Sort Array By Parity

Easy


Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.

2 | 3 |

Return any array that satisfies this condition.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [3,1,2,4]
 9 | Output: [2,4,3,1]
10 | Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [0]
16 | Output: [0]
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= nums.length <= 5000
  • 24 |
  • 0 <= nums[i] <= 5000
  • 25 |
26 |
-------------------------------------------------------------------------------- /0922-sort-array-by-parity-ii/0922-sort-array-by-parity-ii.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var sortArrayByParityII = function(nums) { 6 | let o = 1; 7 | let e = 0; 8 | 9 | let res = []; 10 | for(n of nums) 11 | { 12 | if(n%2==0) 13 | { 14 | res[e] = n; 15 | e +=2; 16 | }else{ 17 | res[o] = n; 18 | o +=2; 19 | } 20 | } 21 | return res; 22 | 23 | }; -------------------------------------------------------------------------------- /0922-sort-array-by-parity-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0922-sort-array-by-parity-ii/README.md: -------------------------------------------------------------------------------- 1 |

922. Sort Array By Parity II

Easy


Given an array of integers nums, half of the integers in nums are odd, and the other half are even.

2 | 3 |

Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.

4 | 5 |

Return any answer array that satisfies this condition.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: nums = [4,2,5,7]
11 | Output: [4,5,2,7]
12 | Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
13 | 
14 | 15 |

Example 2:

16 | 17 |
Input: nums = [2,3]
18 | Output: [2,3]
19 | 
20 | 21 |

 

22 |

Constraints:

23 | 24 |
    25 |
  • 2 <= nums.length <= 2 * 104
  • 26 |
  • nums.length is even.
  • 27 |
  • Half of the integers in nums are even.
  • 28 |
  • 0 <= nums[i] <= 1000
  • 29 |
30 | 31 |

 

32 |

Follow Up: Could you solve it in-place?

33 |
-------------------------------------------------------------------------------- /0961-n-repeated-element-in-size-2n-array/0961-n-repeated-element-in-size-2n-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var repeatedNTimes = function(nums) { 6 | let obj = {}; 7 | for(let n of nums) 8 | { 9 | if(obj[n]) 10 | { 11 | return n; 12 | } 13 | else{ 14 | obj[n] = 1; 15 | } 16 | } 17 | 18 | }; -------------------------------------------------------------------------------- /0961-n-repeated-element-in-size-2n-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1108-defanging-an-ip-address/1108-defanging-an-ip-address.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} address 3 | * @return {string} 4 | */ 5 | var defangIPaddr = function(address) { 6 | address = address.split(""); 7 | for(let i=0; i1108. Defanging an IP Address

Easy


Given a valid (IPv4) IP address, return a defanged version of that IP address.

2 | 3 |

A defanged IP address replaces every period "." with "[.]".

4 | 5 |

 

6 |

Example 1:

7 |
Input: address = "1.1.1.1"
 8 | Output: "1[.]1[.]1[.]1"
 9 | 

Example 2:

10 |
Input: address = "255.100.50.0"
11 | Output: "255[.]100[.]50[.]0"
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • The given address is a valid IPv4 address.
  • 18 |
-------------------------------------------------------------------------------- /1281-subtract-the-product-and-sum-of-digits-of-an-integer/1281-subtract-the-product-and-sum-of-digits-of-an-integer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var subtractProductAndSum = function(n) { 6 | let sum =0; 7 | let pro = 1; 8 | 9 | let a = n.toString().split("").map(Number); 10 | 11 | for(let i =0; i{ 15 | let b = ''; 16 | b += a; 17 | return b; 18 | } 19 | 20 | let splitc = (b) =>{ 21 | let arr = []; 22 | for(let i=0;i1295. Find Numbers with Even Number of Digits

Easy


Given an array nums of integers, return how many of them contain an even number of digits.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: nums = [12,345,2,6,7896]
 7 | Output: 2
 8 | Explanation: 
 9 | 12 contains 2 digits (even number of digits). 
10 | 345 contains 3 digits (odd number of digits). 
11 | 2 contains 1 digit (odd number of digits). 
12 | 6 contains 1 digit (odd number of digits). 
13 | 7896 contains 4 digits (even number of digits). 
14 | Therefore only 12 and 7896 contain an even number of digits.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: nums = [555,901,482,1771]
20 | Output: 1 
21 | Explanation: 
22 | Only 1771 contains an even number of digits.
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 |
    29 |
  • 1 <= nums.length <= 500
  • 30 |
  • 1 <= nums[i] <= 105
  • 31 |
32 |
-------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/1342-number-of-steps-to-reduce-a-number-to-zero.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} num 3 | * @return {number} 4 | */ 5 | var numberOfSteps = function(num) { 6 | let res = 0; 7 | while(num!==0) 8 | { 9 | if(num%2==0) 10 | { 11 | num = num / 2; 12 | res++; 13 | }else 14 | { 15 | num = num -1; 16 | res++; 17 | } 18 | } 19 | return res; 20 | 21 | }; -------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/README.md: -------------------------------------------------------------------------------- 1 |

1342. Number of Steps to Reduce a Number to Zero

Easy


Given an integer num, return the number of steps to reduce it to zero.

2 | 3 |

In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: num = 14
 9 | Output: 6
10 | Explanation: 
11 | Step 1) 14 is even; divide by 2 and obtain 7. 
12 | Step 2) 7 is odd; subtract 1 and obtain 6.
13 | Step 3) 6 is even; divide by 2 and obtain 3. 
14 | Step 4) 3 is odd; subtract 1 and obtain 2. 
15 | Step 5) 2 is even; divide by 2 and obtain 1. 
16 | Step 6) 1 is odd; subtract 1 and obtain 0.
17 | 
18 | 19 |

Example 2:

20 | 21 |
Input: num = 8
22 | Output: 4
23 | Explanation: 
24 | Step 1) 8 is even; divide by 2 and obtain 4. 
25 | Step 2) 4 is even; divide by 2 and obtain 2. 
26 | Step 3) 2 is even; divide by 2 and obtain 1. 
27 | Step 4) 1 is odd; subtract 1 and obtain 0.
28 | 
29 | 30 |

Example 3:

31 | 32 |
Input: num = 123
33 | Output: 12
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 0 <= num <= 106
  • 41 |
42 |
-------------------------------------------------------------------------------- /1365-how-many-numbers-are-smaller-than-the-current-number/1365-how-many-numbers-are-smaller-than-the-current-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var smallerNumbersThanCurrent = function(nums) { 6 | let op = []; 7 | for(let i=0; i1365. How Many Numbers Are Smaller Than the Current Number

Easy


Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

2 | 3 |

Return the answer in an array.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [8,1,2,2,3]
 9 | Output: [4,0,1,1,3]
10 | Explanation: 
11 | For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). 
12 | For nums[1]=1 does not exist any smaller number than it.
13 | For nums[2]=2 there exist one smaller number than it (1). 
14 | For nums[3]=2 there exist one smaller number than it (1). 
15 | For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: nums = [6,5,4,8]
21 | Output: [2,1,0,3]
22 | 
23 | 24 |

Example 3:

25 | 26 |
Input: nums = [7,7,7,7]
27 | Output: [0,0,0,0]
28 | 
29 | 30 |

 

31 |

Constraints:

32 | 33 |
    34 |
  • 2 <= nums.length <= 500
  • 35 |
  • 0 <= nums[i] <= 100
  • 36 |
37 |
-------------------------------------------------------------------------------- /1389-create-target-array-in-the-given-order/1389-create-target-array-in-the-given-order.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number[]} index 4 | * @return {number[]} 5 | */ 6 | var createTargetArray = function(nums, index) { 7 | let target = []; 8 | 9 | for(let i=0; i1389. Create Target Array in the Given Order

Easy


Given two arrays of integers nums and index. Your task is to create target array under the following rules:

2 | 3 |
    4 |
  • Initially target array is empty.
  • 5 |
  • From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
  • 6 |
  • Repeat the previous step until there are no elements to read in nums and index.
  • 7 |
8 | 9 |

Return the target array.

10 | 11 |

It is guaranteed that the insertion operations will be valid.

12 | 13 |

 

14 |

Example 1:

15 | 16 |
Input: nums = [0,1,2,3,4], index = [0,1,2,2,1]
17 | Output: [0,4,1,3,2]
18 | Explanation:
19 | nums       index     target
20 | 0            0        [0]
21 | 1            1        [0,1]
22 | 2            2        [0,1,2]
23 | 3            2        [0,1,3,2]
24 | 4            1        [0,4,1,3,2]
25 | 
26 | 27 |

Example 2:

28 | 29 |
Input: nums = [1,2,3,4,0], index = [0,1,2,3,0]
30 | Output: [0,1,2,3,4]
31 | Explanation:
32 | nums       index     target
33 | 1            0        [1]
34 | 2            1        [1,2]
35 | 3            2        [1,2,3]
36 | 4            3        [1,2,3,4]
37 | 0            0        [0,1,2,3,4]
38 | 
39 | 40 |

Example 3:

41 | 42 |
Input: nums = [1], index = [0]
43 | Output: [1]
44 | 
45 | 46 |

 

47 |

Constraints:

48 | 49 |
    50 |
  • 1 <= nums.length, index.length <= 100
  • 51 |
  • nums.length == index.length
  • 52 |
  • 0 <= nums[i] <= 100
  • 53 |
  • 0 <= index[i] <= i
  • 54 |
55 |
-------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/1480-running-sum-of-1d-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var runningSum = function(nums) { 6 | let res = []; 7 | let sum = 0; 8 | for(let i=0; i1480. Running Sum of 1d Array

Easy


Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

2 | 3 |

Return the running sum of nums.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [1,2,3,4]
 9 | Output: [1,3,6,10]
10 | Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
11 | 12 |

Example 2:

13 | 14 |
Input: nums = [1,1,1,1,1]
15 | Output: [1,2,3,4,5]
16 | Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
17 | 18 |

Example 3:

19 | 20 |
Input: nums = [3,1,2,10,1]
21 | Output: [3,4,6,16,17]
22 | 
23 | 24 |

 

25 |

Constraints:

26 | 27 |
    28 |
  • 1 <= nums.length <= 1000
  • 29 |
  • -10^6 <= nums[i] <= 10^6
  • 30 |
-------------------------------------------------------------------------------- /1491-average-salary-excluding-the-minimum-and-maximum-salary/1491-average-salary-excluding-the-minimum-and-maximum-salary.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} salary 3 | * @return {number} 4 | */ 5 | var average = function(salary) { 6 | let totalsum =0; 7 | let min = salary[0]; 8 | let max = salary[0]; 9 | for(let i=0; i< salary.length; i++) 10 | { 11 | if(salary[i] > max) 12 | { 13 | max = salary[i]; 14 | } 15 | if(salary[i] < min) 16 | { 17 | min = salary[i]; 18 | } 19 | } 20 | 21 | for(let i=0; i1491. Average Salary Excluding the Minimum and Maximum Salary

Easy


You are given an array of unique integers salary where salary[i] is the salary of the ith employee.

2 | 3 |

Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: salary = [4000,3000,1000,2000]
 9 | Output: 2500.00000
10 | Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively.
11 | Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500
12 | 
13 | 14 |

Example 2:

15 | 16 |
Input: salary = [1000,2000,3000]
17 | Output: 2000.00000
18 | Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively.
19 | Average salary excluding minimum and maximum salary is (2000) / 1 = 2000
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • 3 <= salary.length <= 100
  • 27 |
  • 1000 <= salary[i] <= 106
  • 28 |
  • All the integers of salary are unique.
  • 29 |
30 |
-------------------------------------------------------------------------------- /1512-number-of-good-pairs/1512-number-of-good-pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var numIdenticalPairs = function(nums) { 6 | let obj = {}; 7 | let goodPair = 0; 8 | for(let i=0; i1512. Number of Good Pairs

Easy


Given an array of integers nums, return the number of good pairs.

2 | 3 |

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [1,2,3,1,1,3]
 9 | Output: 4
10 | Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [1,1,1,1]
16 | Output: 6
17 | Explanation: Each pair in the array are good.
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: nums = [1,2,3]
23 | Output: 0
24 | 
25 | 26 |

 

27 |

Constraints:

28 | 29 |
    30 |
  • 1 <= nums.length <= 100
  • 31 |
  • 1 <= nums[i] <= 100
  • 32 |
33 |
-------------------------------------------------------------------------------- /1528-shuffle-string/1528-shuffle-string.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {number[]} indices 4 | * @return {string} 5 | */ 6 | var restoreString = function(s, indices) { 7 | let op = s; 8 | op = op.split(""); 9 | 10 | for(let i=0;i1528. Shuffle String

Easy


You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.

2 | 3 |

Return the shuffled string.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3]
 9 | Output: "leetcode"
10 | Explanation: As shown, "codeleet" becomes "leetcode" after shuffling.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: s = "abc", indices = [0,1,2]
16 | Output: "abc"
17 | Explanation: After shuffling, each character remains in its position.
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • s.length == indices.length == n
  • 25 |
  • 1 <= n <= 100
  • 26 |
  • s consists of only lowercase English letters.
  • 27 |
  • 0 <= indices[i] < n
  • 28 |
  • All values of indices are unique.
  • 29 |
30 |
-------------------------------------------------------------------------------- /1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} word1 3 | * @param {string[]} word2 4 | * @return {boolean} 5 | */ 6 | var arrayStringsAreEqual = function(word1, word2) { 7 | word1 = word1.join(""); 8 | word2 = word2.join(""); 9 | if(word1.length !== word2.length) return false 10 | 11 | for(let i=0; i1662. Check If Two String Arrays are Equivalent

Easy


Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

2 | 3 |

A string is represented by an array if the array elements concatenated in order forms the string.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
 9 | Output: true
10 | Explanation:
11 | word1 represents string "ab" + "c" -> "abc"
12 | word2 represents string "a" + "bc" -> "abc"
13 | The strings are the same, so return true.
14 | 15 |

Example 2:

16 | 17 |
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
18 | Output: false
19 | 
20 | 21 |

Example 3:

22 | 23 |
Input: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
24 | Output: true
25 | 
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • 1 <= word1.length, word2.length <= 103
  • 32 |
  • 1 <= word1[i].length, word2[i].length <= 103
  • 33 |
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • 34 |
  • word1[i] and word2[i] consist of lowercase letters.
  • 35 |
36 |
-------------------------------------------------------------------------------- /1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var numberOfMatches = function(n) { 6 | return n-1; 7 | 8 | }; -------------------------------------------------------------------------------- /1688-count-of-matches-in-tournament/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1688-count-of-matches-in-tournament/README.md: -------------------------------------------------------------------------------- 1 |

1688. Count of Matches in Tournament

Easy


You are given an integer n, the number of teams in a tournament that has strange rules:

2 | 3 |
    4 |
  • If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
  • 5 |
  • If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
  • 6 |
7 | 8 |

Return the number of matches played in the tournament until a winner is decided.

9 | 10 |

 

11 |

Example 1:

12 | 13 |
Input: n = 7
14 | Output: 6
15 | Explanation: Details of the tournament: 
16 | - 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
17 | - 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
18 | - 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
19 | Total number of matches = 3 + 2 + 1 = 6.
20 | 
21 | 22 |

Example 2:

23 | 24 |
Input: n = 14
25 | Output: 13
26 | Explanation: Details of the tournament:
27 | - 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
28 | - 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
29 | - 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
30 | - 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
31 | Total number of matches = 7 + 3 + 2 + 1 = 13.
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 1 <= n <= 200
  • 39 |
40 |
-------------------------------------------------------------------------------- /1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {boolean} 4 | */ 5 | var halvesAreAlike = function(s) { 6 | s = s.toLowerCase(); 7 | 8 | let f = Math.floor(s.length/2); 9 | let se = s.length -1; 10 | 11 | 12 | 13 | let a = ""; 14 | let b = ""; 15 | 16 | for(let i=0; i1704. Determine if String Halves Are Alike

Easy


You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

2 | 3 |

Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.

4 | 5 |

Return true if a and b are alike. Otherwise, return false.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: s = "book"
11 | Output: true
12 | Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.
13 | 
14 | 15 |

Example 2:

16 | 17 |
Input: s = "textbook"
18 | Output: false
19 | Explanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.
20 | Notice that the vowel o is counted twice.
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 |
    27 |
  • 2 <= s.length <= 1000
  • 28 |
  • s.length is even.
  • 29 |
  • s consists of uppercase and lowercase letters.
  • 30 |
31 |
-------------------------------------------------------------------------------- /1748-sum-of-unique-elements/1748-sum-of-unique-elements.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var sumOfUnique = function(nums) { 6 | let obj = {}; 7 | 8 | let sum = 0; 9 | for(let n of nums) 10 | { 11 | if(obj[n]) 12 | { 13 | obj[n] +=1; 14 | } 15 | else{ 16 | obj[n] = 1; 17 | } 18 | } 19 | for(k in obj) 20 | { 21 | if(obj[k] ==1) 22 | { 23 | sum+= +(k); 24 | } 25 | } 26 | return sum; 27 | }; -------------------------------------------------------------------------------- /1748-sum-of-unique-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1748-sum-of-unique-elements/README.md: -------------------------------------------------------------------------------- 1 |

1748. Sum of Unique Elements

Easy


You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.

2 | 3 |

Return the sum of all the unique elements of nums.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [1,2,3,2]
 9 | Output: 4
10 | Explanation: The unique elements are [1,3], and the sum is 4.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [1,1,1,1,1]
16 | Output: 0
17 | Explanation: There are no unique elements, and the sum is 0.
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: nums = [1,2,3,4,5]
23 | Output: 15
24 | Explanation: The unique elements are [1,2,3,4,5], and the sum is 15.
25 | 
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • 1 <= nums.length <= 100
  • 32 |
  • 1 <= nums[i] <= 100
  • 33 |
34 |
-------------------------------------------------------------------------------- /1768-merge-strings-alternately/1768-merge-strings-alternately.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} word1 3 | * @param {string} word2 4 | * @return {string} 5 | */ 6 | var mergeAlternately = function(word1, word2) { 7 | let merged = ''; 8 | let w = word1; 9 | let w2 = word2; 10 | 11 | if(w.length > w2.length) 12 | { 13 | for(let i=0; i w.length) 22 | { 23 | for(let i=0; i1768. Merge Strings Alternately

Easy


You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.

2 | 3 |

Return the merged string.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: word1 = "abc", word2 = "pqr"
 9 | Output: "apbqcr"
10 | Explanation: The merged string will be merged as so:
11 | word1:  a   b   c
12 | word2:    p   q   r
13 | merged: a p b q c r
14 | 
15 | 16 |

Example 2:

17 | 18 |
Input: word1 = "ab", word2 = "pqrs"
19 | Output: "apbqrs"
20 | Explanation: Notice that as word2 is longer, "rs" is appended to the end.
21 | word1:  a   b 
22 | word2:    p   q   r   s
23 | merged: a p b q   r   s
24 | 
25 | 26 |

Example 3:

27 | 28 |
Input: word1 = "abcd", word2 = "pq"
29 | Output: "apbqcd"
30 | Explanation: Notice that as word1 is longer, "cd" is appended to the end.
31 | word1:  a   b   c   d
32 | word2:    p   q 
33 | merged: a p b q c   d
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 1 <= word1.length, word2.length <= 100
  • 41 |
  • word1 and word2 consist of lowercase English letters.
  • 42 |
-------------------------------------------------------------------------------- /1816-truncate-sentence/1816-truncate-sentence.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @param {number} k 4 | * @return {string} 5 | */ 6 | var truncateSentence = function(s, k) { 7 | s = s.split(" "); 8 | 9 | 10 | let res = []; 11 | 12 | for(let i=0; i1816. Truncate Sentence

Easy


A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).

2 | 3 |
    4 |
  • For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.
  • 5 |
6 | 7 |

You are given a sentence s​​​​​​ and an integer k​​​​​​. You want to truncate s​​​​​​ such that it contains only the first k​​​​​​ words. Return s​​​​​​ after truncating it.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: s = "Hello how are you Contestant", k = 4
13 | Output: "Hello how are you"
14 | Explanation:
15 | The words in s are ["Hello", "how" "are", "you", "Contestant"].
16 | The first 4 words are ["Hello", "how", "are", "you"].
17 | Hence, you should return "Hello how are you".
18 | 
19 | 20 |

Example 2:

21 | 22 |
Input: s = "What is the solution to this problem", k = 4
23 | Output: "What is the solution"
24 | Explanation:
25 | The words in s are ["What", "is" "the", "solution", "to", "this", "problem"].
26 | The first 4 words are ["What", "is", "the", "solution"].
27 | Hence, you should return "What is the solution".
28 | 29 |

Example 3:

30 | 31 |
Input: s = "chopper is not a tanuki", k = 5
32 | Output: "chopper is not a tanuki"
33 | 
34 | 35 |

 

36 |

Constraints:

37 | 38 |
    39 |
  • 1 <= s.length <= 500
  • 40 |
  • k is in the range [1, the number of words in s].
  • 41 |
  • s consist of only lowercase and uppercase English letters and spaces.
  • 42 |
  • The words in s are separated by a single space.
  • 43 |
  • There are no leading or trailing spaces.
  • 44 |
45 |
-------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/1832-check-if-the-sentence-is-pangram.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} sentence 3 | * @return {boolean} 4 | */ 5 | var checkIfPangram = function(sentence) { 6 | let obj = {}; 7 | for(s of sentence) 8 | { 9 | if(!obj[s]) 10 | { 11 | obj[s] = 1; 12 | } 13 | } 14 | let len = Object.keys(obj).length; 15 | if(len === 26) 16 | { 17 | return true; 18 | }else{ 19 | return false; 20 | } 21 | 22 | }; -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/README.md: -------------------------------------------------------------------------------- 1 |

1832. Check if the Sentence Is Pangram

Easy


A pangram is a sentence where every letter of the English alphabet appears at least once.

2 | 3 |

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
 9 | Output: true
10 | Explanation: sentence contains at least one of every letter of the English alphabet.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: sentence = "leetcode"
16 | Output: false
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= sentence.length <= 1000
  • 24 |
  • sentence consists of lowercase English letters.
  • 25 |
26 |
-------------------------------------------------------------------------------- /1859-sorting-the-sentence/1859-sorting-the-sentence.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {string} 4 | */ 5 | var sortSentence = function(s) { 6 | const letters = s.split(" "); 7 | let result = []; 8 | for(let i = 0; i < letters.length; i++){ 9 | let letter = letters[i]; 10 | const ind = letter.split("").pop(); 11 | result[ind -1 ] = letter.slice(0, -1); 12 | } 13 | 14 | return result.join(" "); 15 | 16 | }; -------------------------------------------------------------------------------- /1859-sorting-the-sentence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1859-sorting-the-sentence/README.md: -------------------------------------------------------------------------------- 1 |

1859. Sorting the Sentence

Easy


A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.

2 | 3 |

A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.

4 | 5 |
    6 |
  • For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
  • 7 |
8 | 9 |

Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.

10 | 11 |

 

12 |

Example 1:

13 | 14 |
Input: s = "is2 sentence4 This1 a3"
15 | Output: "This is a sentence"
16 | Explanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.
17 | 
18 | 19 |

Example 2:

20 | 21 |
Input: s = "Myself2 Me1 I4 and3"
22 | Output: "Me Myself and I"
23 | Explanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.
24 | 
25 | 26 |

 

27 |

Constraints:

28 | 29 |
    30 |
  • 2 <= s.length <= 200
  • 31 |
  • s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.
  • 32 |
  • The number of words in s is between 1 and 9.
  • 33 |
  • The words in s are separated by a single space.
  • 34 |
  • s contains no leading or trailing spaces.
  • 35 |
-------------------------------------------------------------------------------- /1880-check-if-word-equals-summation-of-two-words/1880-check-if-word-equals-summation-of-two-words.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} firstWord 3 | * @param {string} secondWord 4 | * @param {string} targetWord 5 | * @return {boolean} 6 | */ 7 | var isSumEqual = function(firstWord, secondWord, targetWord) { 8 | 9 | let alpha = 'abcdefghij'; 10 | 11 | let w1 = ""; 12 | let w2 = ""; 13 | let w3 = ""; 14 | for(let i=0; i1880. Check if Word Equals Summation of Two Words

Easy


The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).

2 | 3 |

The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.

4 | 5 |
    6 |
  • For example, if s = "acb", we concatenate each letter's letter value, resulting in "021". After converting it, we get 21.
  • 7 |
8 | 9 |

You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.

10 | 11 |

Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.

12 | 13 |

 

14 |

Example 1:

15 | 16 |
Input: firstWord = "acb", secondWord = "cba", targetWord = "cdb"
17 | Output: true
18 | Explanation:
19 | The numerical value of firstWord is "acb" -> "021" -> 21.
20 | The numerical value of secondWord is "cba" -> "210" -> 210.
21 | The numerical value of targetWord is "cdb" -> "231" -> 231.
22 | We return true because 21 + 210 == 231.
23 | 
24 | 25 |

Example 2:

26 | 27 |
Input: firstWord = "aaa", secondWord = "a", targetWord = "aab"
28 | Output: false
29 | Explanation: 
30 | The numerical value of firstWord is "aaa" -> "000" -> 0.
31 | The numerical value of secondWord is "a" -> "0" -> 0.
32 | The numerical value of targetWord is "aab" -> "001" -> 1.
33 | We return false because 0 + 0 != 1.
34 | 
35 | 36 |

Example 3:

37 | 38 |
Input: firstWord = "aaa", secondWord = "a", targetWord = "aaaa"
39 | Output: true
40 | Explanation: 
41 | The numerical value of firstWord is "aaa" -> "000" -> 0.
42 | The numerical value of secondWord is "a" -> "0" -> 0.
43 | The numerical value of targetWord is "aaaa" -> "0000" -> 0.
44 | We return true because 0 + 0 == 0.
45 | 
46 | 47 |

 

48 |

Constraints:

49 | 50 |
    51 |
  • 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
  • 52 |
  • firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.
  • 53 |
54 |
-------------------------------------------------------------------------------- /1920-build-array-from-permutation/1920-build-array-from-permutation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var buildArray = function(nums) { 6 | let ans = []; 7 | for(let i=0; i1920. Build Array from Permutation

Easy


Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.

2 | 3 |

A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [0,2,1,5,3,4]
 9 | Output: [0,1,2,4,5,3]
10 | Explanation: The array ans is built as follows: 
11 | ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
12 |     = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
13 |     = [0,1,2,4,5,3]
14 | 15 |

Example 2:

16 | 17 |
Input: nums = [5,0,1,2,3,4]
18 | Output: [4,5,0,1,2,3]
19 | Explanation: The array ans is built as follows:
20 | ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
21 |     = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
22 |     = [4,5,0,1,2,3]
23 | 24 |

 

25 |

Constraints:

26 | 27 |
    28 |
  • 1 <= nums.length <= 1000
  • 29 |
  • 0 <= nums[i] < nums.length
  • 30 |
  • The elements in nums are distinct.
  • 31 |
32 | 33 |

 

34 |

Follow-up: Can you solve it without using an extra space (i.e., O(1) memory)?

35 |
-------------------------------------------------------------------------------- /1941-check-if-all-characters-have-equal-number-of-occurrences/1941-check-if-all-characters-have-equal-number-of-occurrences.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {boolean} 4 | */ 5 | var areOccurrencesEqual = function(s) { 6 | let obj = {}; 7 | for(se of s) 8 | { 9 | if(obj[se]) 10 | { 11 | obj[se] +=1; 12 | }else{ 13 | obj[se] = 1; 14 | } 15 | } 16 | 17 | let res = []; 18 | for(k in obj) 19 | { 20 | res.push(obj[k]); 21 | } 22 | 23 | let l = 0; 24 | let r = res.length -1; 25 | 26 | while(l<=r) 27 | { 28 | if(res[l] !== res[r]) 29 | { 30 | return false; 31 | } 32 | l++; 33 | r--; 34 | } 35 | return true; 36 | }; -------------------------------------------------------------------------------- /1941-check-if-all-characters-have-equal-number-of-occurrences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1941-check-if-all-characters-have-equal-number-of-occurrences/README.md: -------------------------------------------------------------------------------- 1 |

1941. Check if All Characters Have Equal Number of Occurrences

Easy


Given a string s, return true if s is a good string, or false otherwise.

2 | 3 |

A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: s = "abacbc"
 9 | Output: true
10 | Explanation: The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: s = "aaabb"
16 | Output: false
17 | Explanation: The characters that appear in s are 'a' and 'b'.
18 | 'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.
19 | 
20 | 21 |

 

22 |

Constraints:

23 | 24 |
    25 |
  • 1 <= s.length <= 1000
  • 26 |
  • s consists of lowercase English letters.
  • 27 |
28 |
-------------------------------------------------------------------------------- /2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} word 3 | * @param {character} ch 4 | * @return {string} 5 | */ 6 | var reversePrefix = function(word, ch) { 7 | 8 | let n = 0; 9 | for(let i=0; i2000. Reverse Prefix of Word

Easy


Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.

2 | 3 |
    4 |
  • For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "dcbaefd".
  • 5 |
6 | 7 |

Return the resulting string.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: word = "abcdefd", ch = "d"
13 | Output: "dcbaefd"
14 | Explanation: The first occurrence of "d" is at index 3. 
15 | Reverse the part of word from 0 to 3 (inclusive), the resulting string is "dcbaefd".
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: word = "xyxzxe", ch = "z"
21 | Output: "zxyxxe"
22 | Explanation: The first and only occurrence of "z" is at index 3.
23 | Reverse the part of word from 0 to 3 (inclusive), the resulting string is "zxyxxe".
24 | 
25 | 26 |

Example 3:

27 | 28 |
Input: word = "abcd", ch = "z"
29 | Output: "abcd"
30 | Explanation: "z" does not exist in word.
31 | You should not do any reverse operation, the resulting string is "abcd".
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 1 <= word.length <= 250
  • 39 |
  • word consists of lowercase English letters.
  • 40 |
  • ch is a lowercase English letter.
  • 41 |
42 |
-------------------------------------------------------------------------------- /2006-count-number-of-pairs-with-absolute-difference-k/2006-count-number-of-pairs-with-absolute-difference-k.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} k 4 | * @return {number} 5 | */ 6 | var countKDifference = function(nums, k) { 7 | let res = 0; 8 | for(let i=0; i2006. Count Number of Pairs With Absolute Difference K

Easy


Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.

2 | 3 |

The value of |x| is defined as:

4 | 5 |
    6 |
  • x if x >= 0.
  • 7 |
  • -x if x < 0.
  • 8 |
9 | 10 |

 

11 |

Example 1:

12 | 13 |
Input: nums = [1,2,2,1], k = 1
14 | Output: 4
15 | Explanation: The pairs with an absolute difference of 1 are:
16 | - [1,2,2,1]
17 | - [1,2,2,1]
18 | - [1,2,2,1]
19 | - [1,2,2,1]
20 | 
21 | 22 |

Example 2:

23 | 24 |
Input: nums = [1,3], k = 3
25 | Output: 0
26 | Explanation: There are no pairs with an absolute difference of 3.
27 | 
28 | 29 |

Example 3:

30 | 31 |
Input: nums = [3,2,1,5,4], k = 2
32 | Output: 3
33 | Explanation: The pairs with an absolute difference of 2 are:
34 | - [3,2,1,5,4]
35 | - [3,2,1,5,4]
36 | - [3,2,1,5,4]
37 | 
38 | 39 |

 

40 |

Constraints:

41 | 42 |
    43 |
  • 1 <= nums.length <= 200
  • 44 |
  • 1 <= nums[i] <= 100
  • 45 |
  • 1 <= k <= 99
  • 46 |
47 |
-------------------------------------------------------------------------------- /2032-two-out-of-three/2032-two-out-of-three.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums1 3 | * @param {number[]} nums2 4 | * @param {number[]} nums3 5 | * @return {number[]} 6 | */ 7 | var twoOutOfThree = function(nums1, nums2, nums3) { 8 | let ar1 = new Array(101).fill(0) 9 | let ar2 = new Array(101).fill(0) 10 | let ar3 = new Array(101).fill(0) 11 | 12 | for (let num of nums1) { 13 | ar1[num] = 1 14 | } 15 | 16 | for (let num of nums2) { 17 | ar2[num] = 1 18 | } 19 | 20 | for (let num of nums3) { 21 | ar3[num] = 1 22 | } 23 | 24 | let obj = []; 25 | for (let i = 0; i < 101; i++) { 26 | if (ar1[i] + ar2[i] + ar3[i] >=2){ 27 | 28 | obj.push(i); 29 | } 30 | } 31 | return obj; 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /2032-two-out-of-three/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2032-two-out-of-three/README.md: -------------------------------------------------------------------------------- 1 |

2032. Two Out of Three

Easy


Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order. 2 |

 

3 |

Example 1:

4 | 5 |
Input: nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
 6 | Output: [3,2]
 7 | Explanation: The values that are present in at least two arrays are:
 8 | - 3, in all three arrays.
 9 | - 2, in nums1 and nums2.
10 | 
11 | 12 |

Example 2:

13 | 14 |
Input: nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]
15 | Output: [2,3,1]
16 | Explanation: The values that are present in at least two arrays are:
17 | - 2, in nums2 and nums3.
18 | - 3, in nums1 and nums2.
19 | - 1, in nums1 and nums3.
20 | 
21 | 22 |

Example 3:

23 | 24 |
Input: nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]
25 | Output: []
26 | Explanation: No value is present in at least two arrays.
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • 1 <= nums1.length, nums2.length, nums3.length <= 100
  • 34 |
  • 1 <= nums1[i], nums2[j], nums3[k] <= 100
  • 35 |
36 |
-------------------------------------------------------------------------------- /2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} words 3 | * @return {string} 4 | */ 5 | var firstPalindrome = function(words) { 6 | 7 | for(let i=0; i{ 20 | let l = 0; 21 | let r = s.length -1; 22 | while(l2108. Find First Palindromic String in the Array

Easy


Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".

2 | 3 |

A string is palindromic if it reads the same forward and backward.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: words = ["abc","car","ada","racecar","cool"]
 9 | Output: "ada"
10 | Explanation: The first string that is palindromic is "ada".
11 | Note that "racecar" is also palindromic, but it is not the first.
12 | 
13 | 14 |

Example 2:

15 | 16 |
Input: words = ["notapalindrome","racecar"]
17 | Output: "racecar"
18 | Explanation: The first and only string that is palindromic is "racecar".
19 | 
20 | 21 |

Example 3:

22 | 23 |
Input: words = ["def","ghi"]
24 | Output: ""
25 | Explanation: There are no palindromic strings, so the empty string is returned.
26 | 
27 | 28 |

 

29 |

Constraints:

30 | 31 |
    32 |
  • 1 <= words.length <= 100
  • 33 |
  • 1 <= words[i].length <= 100
  • 34 |
  • words[i] consists only of lowercase English letters.
  • 35 |
36 |
-------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var rearrangeArray = function(nums) { 6 | let p =0; 7 | let n =1; 8 | let res = []; 9 | 10 | for(let i=0; i<=nums.length-1; i++) 11 | { 12 | if(nums[i]<0) 13 | { 14 | res[n]= nums[i] 15 | n+=2; 16 | } 17 | else{ 18 | res[p] = nums[i]; 19 | p+=2; 20 | } 21 | } 22 | return res; 23 | 24 | }; -------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/README.md: -------------------------------------------------------------------------------- 1 |

2149. Rearrange Array Elements by Sign

Medium


You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.

2 | 3 |

You should rearrange the elements of nums such that the modified array follows the given conditions:

4 | 5 |
    6 |
  1. Every consecutive pair of integers have opposite signs.
  2. 7 |
  3. For all integers with the same sign, the order in which they were present in nums is preserved.
  4. 8 |
  5. The rearranged array begins with a positive integer.
  6. 9 |
10 | 11 |

Return the modified array after rearranging the elements to satisfy the aforementioned conditions.

12 | 13 |

 

14 |

Example 1:

15 | 16 |
Input: nums = [3,1,-2,-5,2,-4]
17 | Output: [3,-2,1,-5,2,-4]
18 | Explanation:
19 | The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].
20 | The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].
21 | Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.  
22 | 
23 | 24 |

Example 2:

25 | 26 |
Input: nums = [-1,1]
27 | Output: [1,-1]
28 | Explanation:
29 | 1 is the only positive integer and -1 the only negative integer in nums.
30 | So nums is rearranged to [1,-1].
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • 2 <= nums.length <= 2 * 105
  • 38 |
  • nums.length is even
  • 39 |
  • 1 <= |nums[i]| <= 105
  • 40 |
  • nums consists of equal number of positive and negative integers.
  • 41 |
42 |
-------------------------------------------------------------------------------- /2161-partition-array-according-to-given-pivot/2161-partition-array-according-to-given-pivot.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} pivot 4 | * @return {number[]} 5 | */ 6 | var pivotArray = function(nums, pivot) { 7 | 8 | let sml = []; 9 | let big = []; 10 | let eql = []; 11 | 12 | for(let i=0; i pivot) 19 | { 20 | big.push(nums[i]); 21 | } 22 | else{ 23 | eql.push(nums[i]); 24 | } 25 | } 26 | return sml.concat(eql, big); 27 | }; -------------------------------------------------------------------------------- /2161-partition-array-according-to-given-pivot/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2161-partition-array-according-to-given-pivot/README.md: -------------------------------------------------------------------------------- 1 |

2161. Partition Array According to Given Pivot

Medium


You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:

2 | 3 |
    4 |
  • Every element less than pivot appears before every element greater than pivot.
  • 5 |
  • Every element equal to pivot appears in between the elements less than and greater than pivot.
  • 6 |
  • The relative order of the elements less than pivot and the elements greater than pivot is maintained. 7 |
      8 |
    • More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. For elements less than pivot, if i < j and nums[i] < pivot and nums[j] < pivot, then pi < pj. Similarly for elements greater than pivot, if i < j and nums[i] > pivot and nums[j] > pivot, then pi < pj.
    • 9 |
    10 |
  • 11 |
12 | 13 |

Return nums after the rearrangement.

14 | 15 |

 

16 |

Example 1:

17 | 18 |
Input: nums = [9,12,5,10,14,3,10], pivot = 10
19 | Output: [9,5,3,10,10,12,14]
20 | Explanation: 
21 | The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.
22 | The elements 12 and 14 are greater than the pivot so they are on the right side of the array.
23 | The relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.
24 | 
25 | 26 |

Example 2:

27 | 28 |
Input: nums = [-3,4,3,2], pivot = 2
29 | Output: [-3,2,4,3]
30 | Explanation: 
31 | The element -3 is less than the pivot so it is on the left side of the array.
32 | The elements 4 and 3 are greater than the pivot so they are on the right side of the array.
33 | The relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 1 <= nums.length <= 105
  • 41 |
  • -106 <= nums[i] <= 106
  • 42 |
  • pivot equals to an element of nums.
  • 43 |
44 |
-------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/2169-count-operations-to-obtain-zero.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} num1 3 | * @param {number} num2 4 | * @return {number} 5 | */ 6 | var countOperations = function(num1, num2) { 7 | let count = 0; 8 | if(num1 ==0 || num2 ==0) return count; 9 | while(num1 !==0 ) 10 | { 11 | if(num1 < num2) 12 | { 13 | num2 = num2 - num1; 14 | count++; 15 | }else if(num1 > num2) 16 | { 17 | num1 = num1 - num2; 18 | count++; 19 | } 20 | else if(num1 == num2) 21 | { 22 | num1 = num1 - num2; 23 | count++; 24 | } 25 | } 26 | return count; 27 | 28 | }; -------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/README.md: -------------------------------------------------------------------------------- 1 |

2169. Count Operations to Obtain Zero

Easy


You are given two non-negative integers num1 and num2.

2 | 3 |

In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.

4 | 5 |
    6 |
  • For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.
  • 7 |
8 | 9 |

Return the number of operations required to make either num1 = 0 or num2 = 0.

10 | 11 |

 

12 |

Example 1:

13 | 14 |
Input: num1 = 2, num2 = 3
15 | Output: 3
16 | Explanation: 
17 | - Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.
18 | - Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.
19 | - Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.
20 | Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.
21 | So the total number of operations required is 3.
22 | 
23 | 24 |

Example 2:

25 | 26 |
Input: num1 = 10, num2 = 10
27 | Output: 1
28 | Explanation: 
29 | - Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.
30 | Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.
31 | So the total number of operations required is 1.
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 0 <= num1, num2 <= 105
  • 39 |
40 |
-------------------------------------------------------------------------------- /2235-add-two-integers/2235-add-two-integers.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} num1 3 | * @param {number} num2 4 | * @return {number} 5 | */ 6 | var sum = function(num1, num2) { 7 | return num1 + num2; 8 | }; -------------------------------------------------------------------------------- /2235-add-two-integers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2235-add-two-integers/README.md: -------------------------------------------------------------------------------- 1 |

2235. Add Two Integers

Easy


Given two integers num1 and num2, return the sum of the two integers. 2 |

 

3 |

Example 1:

4 | 5 |
Input: num1 = 12, num2 = 5
 6 | Output: 17
 7 | Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: num1 = -10, num2 = 4
13 | Output: -6
14 | Explanation: num1 + num2 = -6, so -6 is returned.
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • -100 <= num1, num2 <= 100
  • 22 |
23 |
-------------------------------------------------------------------------------- /2351-first-letter-to-appear-twice/2351-first-letter-to-appear-twice.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {character} 4 | */ 5 | var repeatedCharacter = function(s) { 6 | let obj = {}; 7 | for(se of s) 8 | { 9 | if(obj[se]) 10 | { 11 | return se; 12 | }else{ 13 | obj[se] = 1; 14 | } 15 | } 16 | 17 | }; -------------------------------------------------------------------------------- /2351-first-letter-to-appear-twice/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2351-first-letter-to-appear-twice/README.md: -------------------------------------------------------------------------------- 1 |

2351. First Letter to Appear Twice

Easy


Given a string s consisting of lowercase English letters, return the first letter to appear twice.

2 | 3 |

Note:

4 | 5 |
    6 |
  • A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.
  • 7 |
  • s will contain at least one letter that appears twice.
  • 8 |
9 | 10 |

 

11 |

Example 1:

12 | 13 |
Input: s = "abccbaacz"
14 | Output: "c"
15 | Explanation:
16 | The letter 'a' appears on the indexes 0, 5 and 6.
17 | The letter 'b' appears on the indexes 1 and 4.
18 | The letter 'c' appears on the indexes 2, 3 and 7.
19 | The letter 'z' appears on the index 8.
20 | The letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.
21 | 
22 | 23 |

Example 2:

24 | 25 |
Input: s = "abcdd"
26 | Output: "d"
27 | Explanation:
28 | The only letter that appears twice is 'd' so we return 'd'.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • 2 <= s.length <= 100
  • 36 |
  • s consists of lowercase English letters.
  • 37 |
  • s has at least one repeated letter.
  • 38 |
39 |
-------------------------------------------------------------------------------- /2396-strictly-palindromic-number/2396-strictly-palindromic-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {boolean} 4 | */ 5 | var isStrictlyPalindromic = function(n) { 6 | return false; 7 | 8 | }; -------------------------------------------------------------------------------- /2396-strictly-palindromic-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2396-strictly-palindromic-number/README.md: -------------------------------------------------------------------------------- 1 |

2396. Strictly Palindromic Number

Medium


An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.

2 | 3 |

Given an integer n, return true if n is strictly palindromic and false otherwise.

4 | 5 |

A string is palindromic if it reads the same forward and backward.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: n = 9
11 | Output: false
12 | Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
13 | In base 3: 9 = 100 (base 3), which is not palindromic.
14 | Therefore, 9 is not strictly palindromic so we return false.
15 | Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: n = 4
21 | Output: false
22 | Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
23 | Therefore, we return false.
24 | 
25 | 
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • 4 <= n <= 105
  • 32 |
33 |
-------------------------------------------------------------------------------- /2413-smallest-even-multiple/2413-smallest-even-multiple.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var smallestEvenMultiple = function(n) { 6 | if(n%2==0) 7 | { 8 | return n; 9 | }else{ 10 | return n*2 11 | } 12 | 13 | 14 | }; -------------------------------------------------------------------------------- /2413-smallest-even-multiple/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2413-smallest-even-multiple/README.md: -------------------------------------------------------------------------------- 1 |

2413. Smallest Even Multiple

Easy


Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. 2 |

 

3 |

Example 1:

4 | 5 |
Input: n = 5
 6 | Output: 10
 7 | Explanation: The smallest multiple of both 5 and 2 is 10.
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: n = 6
13 | Output: 6
14 | Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 1 <= n <= 150
  • 22 |
23 |
-------------------------------------------------------------------------------- /2418-sort-the-people/2418-sort-the-people.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} names 3 | * @param {number[]} heights 4 | * @return {string[]} 5 | */ 6 | var sortPeople = function(names, heights) { 7 | 8 | let arr = []; 9 | 10 | for(let i=0; i b[1] - a[1]); 15 | let sol = arr.map(name => name[0]); 16 | return sol; 17 | 18 | 19 | }; -------------------------------------------------------------------------------- /2418-sort-the-people/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2418-sort-the-people/README.md: -------------------------------------------------------------------------------- 1 |

2418. Sort the People

Easy


You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.

2 | 3 |

For each index i, names[i] and heights[i] denote the name and height of the ith person.

4 | 5 |

Return names sorted in descending order by the people's heights.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: names = ["Mary","John","Emma"], heights = [180,165,170]
11 | Output: ["Mary","Emma","John"]
12 | Explanation: Mary is the tallest, followed by Emma and John.
13 | 
14 | 15 |

Example 2:

16 | 17 |
Input: names = ["Alice","Bob","Bob"], heights = [155,185,150]
18 | Output: ["Bob","Alice","Bob"]
19 | Explanation: The first Bob is the tallest, followed by Alice and the second Bob.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • n == names.length == heights.length
  • 27 |
  • 1 <= n <= 103
  • 28 |
  • 1 <= names[i].length <= 20
  • 29 |
  • 1 <= heights[i] <= 105
  • 30 |
  • names[i] consists of lower and upper case English letters.
  • 31 |
  • All the values of heights are distinct.
  • 32 |
33 |
-------------------------------------------------------------------------------- /2427-number-of-common-factors/2427-number-of-common-factors.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} a 3 | * @param {number} b 4 | * @return {number} 5 | */ 6 | var commonFactors = function(a, b) { 7 | let res = []; 8 | 9 | for(let i=1; i<=a; i++) 10 | { 11 | if(a%i ==0) 12 | { 13 | res.push(i); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | 21 | let res1 = []; 22 | 23 | for(let i=1; i<=b; i++) 24 | { 25 | if(b%i ==0) 26 | { 27 | res1.push(i); 28 | } 29 | } 30 | 31 | 32 | let count = 0; 33 | 34 | for(let i=0; i2442. Count Number of Distinct Integers After Reverse Operations

Medium


You are given an array nums consisting of positive integers.

2 | 3 |

You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.

4 | 5 |

Return the number of distinct integers in the final array.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: nums = [1,13,10,12,31]
11 | Output: 6
12 | Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
13 | The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.
14 | The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
15 | 16 |

Example 2:

17 | 18 |
Input: nums = [2,2,2]
19 | Output: 1
20 | Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].
21 | The number of distinct integers in this array is 1 (The number 2).
22 | 
23 | 24 |

 

25 |

Constraints:

26 | 27 |
    28 |
  • 1 <= nums.length <= 105
  • 29 |
  • 1 <= nums[i] <= 106
  • 30 |
31 |
-------------------------------------------------------------------------------- /2469-convert-the-temperature/2469-convert-the-temperature.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} celsius 3 | * @return {number[]} 4 | */ 5 | var convertTemperature = function(celsius) { 6 | let kelvin = celsius + 273.15; 7 | let Fahrenheit = celsius * 1.80 + 32.00; 8 | return [kelvin, Fahrenheit]; 9 | 10 | }; -------------------------------------------------------------------------------- /2469-convert-the-temperature/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2469-convert-the-temperature/README.md: -------------------------------------------------------------------------------- 1 |

2469. Convert the Temperature

Easy


You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.

2 | 3 |

You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].

4 | 5 |

Return the array ans. Answers within 10-5 of the actual answer will be accepted.

6 | 7 |

Note that:

8 | 9 |
    10 |
  • Kelvin = Celsius + 273.15
  • 11 |
  • Fahrenheit = Celsius * 1.80 + 32.00
  • 12 |
13 | 14 |

 

15 |

Example 1:

16 | 17 |
Input: celsius = 36.50
18 | Output: [309.65000,97.70000]
19 | Explanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.
20 | 
21 | 22 |

Example 2:

23 | 24 |
Input: celsius = 122.11
25 | Output: [395.26000,251.79800]
26 | Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • 0 <= celsius <= 1000
  • 34 |
35 |
-------------------------------------------------------------------------------- /2500-delete-greatest-value-in-each-row/2500-delete-greatest-value-in-each-row.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[][]} grid 3 | * @return {number} 4 | */ 5 | var deleteGreatestValue = function(grid) { 6 | let res = 0; 7 | for (let arr of grid) { 8 | arr.sort((a, b) => b - a); 9 | } 10 | for (let i = 0; i < grid[0].length; i++) { 11 | let max = -Infinity; 12 | for (let arr of grid) { 13 | max = Math.max(max, arr[i]); 14 | } 15 | res += max; 16 | } 17 | return res; 18 | 19 | }; -------------------------------------------------------------------------------- /2500-delete-greatest-value-in-each-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2500-delete-greatest-value-in-each-row/README.md: -------------------------------------------------------------------------------- 1 |

2500. Delete Greatest Value in Each Row

Easy


You are given an m x n matrix grid consisting of positive integers.

2 | 3 |

Perform the following operation until grid becomes empty:

4 | 5 |
    6 |
  • Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.
  • 7 |
  • Add the maximum of deleted elements to the answer.
  • 8 |
9 | 10 |

Note that the number of columns decreases by one after each operation.

11 | 12 |

Return the answer after performing the operations described above.

13 | 14 |

 

15 |

Example 1:

16 | 17 |
Input: grid = [[1,2,4],[3,3,1]]
18 | Output: 8
19 | Explanation: The diagram above shows the removed values in each step.
20 | - In the first operation, we remove 4 from the first row and 3 from the second row (notice that, there are two cells with value 3 and we can remove any of them). We add 4 to the answer.
21 | - In the second operation, we remove 2 from the first row and 3 from the second row. We add 3 to the answer.
22 | - In the third operation, we remove 1 from the first row and 1 from the second row. We add 1 to the answer.
23 | The final answer = 4 + 3 + 1 = 8.
24 | 
25 | 26 |

Example 2:

27 | 28 |
Input: grid = [[10]]
29 | Output: 10
30 | Explanation: The diagram above shows the removed values in each step.
31 | - In the first operation, we remove 10 from the first row. We add 10 to the answer.
32 | The final answer = 10.
33 | 
34 | 35 |

 

36 |

Constraints:

37 | 38 |
    39 |
  • m == grid.length
  • 40 |
  • n == grid[i].length
  • 41 |
  • 1 <= m, n <= 50
  • 42 |
  • 1 <= grid[i][j] <= 100
  • 43 |
44 |
-------------------------------------------------------------------------------- /2520-count-the-digits-that-divide-a-number/2520-count-the-digits-that-divide-a-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} num 3 | * @return {number} 4 | */ 5 | var countDigits = function(num) { 6 | let count = 0; 7 | 8 | for (let i = 0; i < String(num).length; i++) { 9 | if (num % Number(String(num)[i]) === 0) count++ 10 | } 11 | 12 | return count; 13 | }; -------------------------------------------------------------------------------- /2520-count-the-digits-that-divide-a-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2520-count-the-digits-that-divide-a-number/README.md: -------------------------------------------------------------------------------- 1 |

2520. Count the Digits That Divide a Number

Easy


Given an integer num, return the number of digits in num that divide num.

2 | 3 |

An integer val divides nums if nums % val == 0.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: num = 7
 9 | Output: 1
10 | Explanation: 7 divides itself, hence the answer is 1.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: num = 121
16 | Output: 2
17 | Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.
18 | 
19 | 20 |

Example 3:

21 | 22 |
Input: num = 1248
23 | Output: 4
24 | Explanation: 1248 is divisible by all of its digits, hence the answer is 4.
25 | 
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • 1 <= num <= 109
  • 32 |
  • num does not contain 0 as one of its digits.
  • 33 |
34 |
-------------------------------------------------------------------------------- /2529-maximum-count-of-positive-integer-and-negative-integer/2529-maximum-count-of-positive-integer-and-negative-integer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var maximumCount = function(nums) { 6 | let pos = 0; 7 | let neg = 0; 8 | 9 | for(let i=0; i0) 15 | { 16 | pos++; 17 | } 18 | } 19 | 20 | 21 | if(pos >= neg) 22 | { 23 | return pos; 24 | 25 | }else{ 26 | return neg; 27 | } 28 | 29 | }; -------------------------------------------------------------------------------- /2529-maximum-count-of-positive-integer-and-negative-integer/README.md: -------------------------------------------------------------------------------- 1 |

2529. Maximum Count of Positive Integer and Negative Integer

Easy


Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.

2 | 3 |
    4 |
  • In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.
  • 5 |
6 | 7 |

Note that 0 is neither positive nor negative.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: nums = [-2,-1,-1,1,2,3]
13 | Output: 3
14 | Explanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: nums = [-3,-2,-1,0,0,1,2]
20 | Output: 3
21 | Explanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.
22 | 
23 | 24 |

Example 3:

25 | 26 |
Input: nums = [5,20,66,1314]
27 | Output: 4
28 | Explanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • 1 <= nums.length <= 2000
  • 36 |
  • -2000 <= nums[i] <= 2000
  • 37 |
  • nums is sorted in a non-decreasing order.
  • 38 |
39 | 40 |

 

41 |

Follow up: Can you solve the problem in O(log(n)) time complexity?

42 |
-------------------------------------------------------------------------------- /2535-difference-between-element-sum-and-digit-sum-of-an-array/2535-difference-between-element-sum-and-digit-sum-of-an-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var differenceOfSum = function(nums) { 6 | let ans1 = 0; 7 | let ans2 =0; 8 | let nums1 = nums.toString().split("").map(Number); 9 | 10 | for(let i=0; i2535. Difference Between Element Sum and Digit Sum of an Array

Easy


You are given a positive integer array nums.

2 | 3 |
    4 |
  • The element sum is the sum of all the elements in nums.
  • 5 |
  • The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.
  • 6 |
7 | 8 |

Return the absolute difference between the element sum and digit sum of nums.

9 | 10 |

Note that the absolute difference between two integers x and y is defined as |x - y|.

11 | 12 |

 

13 |

Example 1:

14 | 15 |
Input: nums = [1,15,6,3]
16 | Output: 9
17 | Explanation: 
18 | The element sum of nums is 1 + 15 + 6 + 3 = 25.
19 | The digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.
20 | The absolute difference between the element sum and digit sum is |25 - 16| = 9.
21 | 
22 | 23 |

Example 2:

24 | 25 |
Input: nums = [1,2,3,4]
26 | Output: 0
27 | Explanation:
28 | The element sum of nums is 1 + 2 + 3 + 4 = 10.
29 | The digit sum of nums is 1 + 2 + 3 + 4 = 10.
30 | The absolute difference between the element sum and digit sum is |10 - 10| = 0.
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • 1 <= nums.length <= 2000
  • 38 |
  • 1 <= nums[i] <= 2000
  • 39 |
40 |
-------------------------------------------------------------------------------- /2544-alternating-digit-sum/2544-alternating-digit-sum.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var alternateDigitSum = function(n) { 6 | let sum =0; 7 | let a = n.toString().split("").map(Number); 8 | for(let i=0; i2544. Alternating Digit Sum

Easy


You are given a positive integer n. Each digit of n has a sign according to the following rules:

2 | 3 |
    4 |
  • The most significant digit is assigned a positive sign.
  • 5 |
  • Each other digit has an opposite sign to its adjacent digits.
  • 6 |
7 | 8 |

Return the sum of all digits with their corresponding sign.

9 | 10 |

 

11 |

Example 1:

12 | 13 |
Input: n = 521
14 | Output: 4
15 | Explanation: (+5) + (-2) + (+1) = 4.
16 | 
17 | 18 |

Example 2:

19 | 20 |
Input: n = 111
21 | Output: 1
22 | Explanation: (+1) + (-1) + (+1) = 1.
23 | 
24 | 25 |

Example 3:

26 | 27 |
Input: n = 886996
28 | Output: 0
29 | Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.
30 | 
31 | 32 |

 

33 |

Constraints:

34 | 35 |
    36 |
  • 1 <= n <= 109
  • 37 |
38 | 39 |

 

40 | 47 |
-------------------------------------------------------------------------------- /2553-separate-the-digits-in-an-array/2553-separate-the-digits-in-an-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var separateDigits = function(nums) { 6 | let res = nums.join("").split("").map(Number); 7 | return res; 8 | }; -------------------------------------------------------------------------------- /2553-separate-the-digits-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2553-separate-the-digits-in-an-array/README.md: -------------------------------------------------------------------------------- 1 |

2553. Separate the Digits in an Array

Easy


Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.

2 | 3 |

To separate the digits of an integer is to get all the digits it has in the same order.

4 | 5 |
    6 |
  • For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].
  • 7 |
8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: nums = [13,25,83,77]
13 | Output: [1,3,2,5,8,3,7,7]
14 | Explanation: 
15 | - The separation of 13 is [1,3].
16 | - The separation of 25 is [2,5].
17 | - The separation of 83 is [8,3].
18 | - The separation of 77 is [7,7].
19 | answer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.
20 | 
21 | 22 |

Example 2:

23 | 24 |
Input: nums = [7,1,3,9]
25 | Output: [7,1,3,9]
26 | Explanation: The separation of each integer in nums is itself.
27 | answer = [7,1,3,9].
28 | 
29 | 30 |

 

31 |

Constraints:

32 | 33 |
    34 |
  • 1 <= nums.length <= 1000
  • 35 |
  • 1 <= nums[i] <= 105
  • 36 |
37 |
-------------------------------------------------------------------------------- /2574-left-and-right-sum-differences/2574-left-and-right-sum-differences.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var leftRigthDifference = function(nums) { 6 | var leftSum = new Array(); 7 | leftSum[0] = 0; 8 | 9 | var rightSum = new Array(); 10 | rightSum[nums.length-1] = 0; 11 | 12 | var answer = new Array(); 13 | for(var i = 0; i< nums.length ; i++){ 14 | leftSum[i+1] = leftSum[i] + nums[i]; 15 | } 16 | for(var i = nums.length - 1; i > 0; i--){ 17 | rightSum[i-1] = rightSum[i] + nums[i]; 18 | } 19 | 20 | for(var i = 0; i< nums.length; i++){ 21 | var j = leftSum[i] - rightSum[i]; 22 | if(j > 0){ 23 | answer[i] = j; 24 | } 25 | else{ 26 | answer[i] = -1*j; 27 | } 28 | } 29 | return answer; 30 | 31 | }; -------------------------------------------------------------------------------- /2574-left-and-right-sum-differences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2574-left-and-right-sum-differences/README.md: -------------------------------------------------------------------------------- 1 |

2574. Left and Right Sum Differences

Easy


Given a 0-indexed integer array nums, find a 0-indexed integer array answer where:

2 | 3 |
    4 |
  • answer.length == nums.length.
  • 5 |
  • answer[i] = |leftSum[i] - rightSum[i]|.
  • 6 |
7 | 8 |

Where:

9 | 10 |
    11 |
  • leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.
  • 12 |
  • rightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.
  • 13 |
14 | 15 |

Return the array answer.

16 | 17 |

 

18 |

Example 1:

19 | 20 |
Input: nums = [10,4,8,3]
21 | Output: [15,1,11,22]
22 | Explanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].
23 | The array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].
24 | 
25 | 26 |

Example 2:

27 | 28 |
Input: nums = [1]
29 | Output: [0]
30 | Explanation: The array leftSum is [0] and the array rightSum is [0].
31 | The array answer is [|0 - 0|] = [0].
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 1 <= nums.length <= 1000
  • 39 |
  • 1 <= nums[i] <= 105
  • 40 |
41 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Resurfacing in Code Waters: Diving Deep into DSA Once More 🌊🔍 2 | 3 | 4 | 5 | ![coder](https://github.com/Md-sahil-a/Data-Structures-Algorithms/assets/77974484/301357e9-31c6-4ae0-b41a-8561d5268bcf) 6 | -------------------------------------------------------------------------------- /duplicate-zeros/README.md: -------------------------------------------------------------------------------- 1 |

 Duplicate Zeros


Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.

2 | 3 |

Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: arr = [1,0,2,3,0,4,5,0]
 9 | Output: [1,0,0,2,3,0,0,4]
10 | Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: arr = [1,2,3]
16 | Output: [1,2,3]
17 | Explanation: After calling your function, the input array is modified to: [1,2,3]
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= arr.length <= 104
  • 25 |
  • 0 <= arr[i] <= 9
  • 26 |
27 |
-------------------------------------------------------------------------------- /duplicate-zeros/duplicate-zeros.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} arr 3 | * @return {void} Do not return anything, modify arr in-place instead. 4 | */ 5 | var duplicateZeros = function(arr) { 6 | for (let i = 0 ; i < arr.length; i++) { 7 | if (!arr[i]) { 8 | arr.splice(i, 0, 0); 9 | arr.pop(); 10 | i++; 11 | } 12 | } 13 | }; -------------------------------------------------------------------------------- /find-numbers-with-even-number-of-digits/README.md: -------------------------------------------------------------------------------- 1 |

 Find Numbers with Even Number of Digits


Given an array nums of integers, return how many of them contain an even number of digits.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: nums = [12,345,2,6,7896]
 7 | Output: 2
 8 | Explanation: 
 9 | 12 contains 2 digits (even number of digits). 
10 | 345 contains 3 digits (odd number of digits). 
11 | 2 contains 1 digit (odd number of digits). 
12 | 6 contains 1 digit (odd number of digits). 
13 | 7896 contains 4 digits (even number of digits). 
14 | Therefore only 12 and 7896 contain an even number of digits.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: nums = [555,901,482,1771]
20 | Output: 1 
21 | Explanation: 
22 | Only 1771 contains an even number of digits.
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 |
    29 |
  • 1 <= nums.length <= 500
  • 30 |
  • 1 <= nums[i] <= 105
  • 31 |
32 |
-------------------------------------------------------------------------------- /find-numbers-with-even-number-of-digits/find-numbers-with-even-number-of-digits.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var findNumbers = function(nums) { 6 | let res = 0; 7 | 8 | for(let i=0; i  Squares of a Sorted Array

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: nums = [-4,-1,0,3,10]
 7 | Output: [0,1,9,16,100]
 8 | Explanation: After squaring, the array becomes [16,1,0,9,100].
 9 | After sorting, it becomes [0,1,9,16,100].
10 | 
11 | 12 |

Example 2:

13 | 14 |
Input: nums = [-7,-3,2,3,11]
15 | Output: [4,9,9,49,121]
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • 1 <= nums.length <= 104
  • 23 |
  • -104 <= nums[i] <= 104
  • 24 |
  • nums is sorted in non-decreasing order.
  • 25 |
26 | 27 |

 

28 | Follow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?
-------------------------------------------------------------------------------- /squares-of-a-sorted-array/squares-of-a-sorted-array.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number[]} 4 | */ 5 | var sortedSquares = function(nums) { 6 | 7 | let res = []; 8 | for(let i =0; ia-b); 13 | 14 | 15 | }; --------------------------------------------------------------------------------