LeetCode - Array Problems
- Source:
Example
import { threeSumClosest } from '../../array';
console.log(threeSumClosest([-1,2,1,-4], 1); // 2
- Source:
Example
import { threeSum } from '../../array';
console.log(threeSum([-1,0,1,2,-1,-4]); // [[-1,-1,2],[-1,0,1]]
- Source:
Example
import { canMakeSubsequence } from '../../array';
console.log(canMakeSubsequence('abc', 'ad'); // true
- Source:
Example
import { maxArea } from '../../array';
console.log(maxArea([1,8,6,2,5,4,8,3,7]); // 49
- Source:
Example
import { countPairsOptimal } from '../../array';
console.log(countPairsOptimal([-1,1,2,3,1]); // 2
- Source:
Example
import { getAverages } from '../../array';
console.log(getAverages([7,4,3,9,1,8,5,2,6], 3); // [-1,-1,-1,5,4,4,-1,-1,-1]
Example
import { characterReplacement } from '../../array';
console.log(characterReplacement('ABAB', 2); // 4
- Source:
Example
import { maxTurbulenceSize } from '../../array';
console.log(maxTurbulenceSize([9,4,2,10,7,8,8,1,9]); // 5
Example
import { maxSubarraySumCircular } from '../../array';
console.log(maxSubarraySumCircular([5,-3,5]); // 10
- Source:
Example
import { checkInclusion } from '../../array';
console.log(checkInclusion('ab', 'eidbaooo'); // true
Example
import { searchInRotatedArray } from '../../array';
console.log(searchInRotatedArray([4,5,6,7,0,1,2], 0)); // 4
Example
import { checkStrings } from '../../array';
console.log(checkStrings('abcdba', 'cabdab'); // true
- Source:
Example
import { trap } from '../../array';
console.log(trap([0,1,0,2,1,0,1,3,2,1,2,1]); // 6
Methods
(inner) canMakeSubsequence(str1, str2) → {boolean}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
str1 |
string
|
main string. |
str2 |
string
|
substring |
Returns:
- Type:
-
boolean
true if subsequence can be make out of str1, otherwise false
(inner) characterReplacement(s, k) → {number}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
s |
string
|
string. |
k |
k
|
number upto which max replacements are allowed |
Returns:
- Type:
-
number
length of the longest substring
(inner) checkInclusion(s1, s2) → {boolean}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
s1 |
string
|
string. |
s2 |
string
|
string |
Returns:
- Type:
-
boolean
true if s1 is permutation of s2, otherwise false
(inner) checkStrings(s1, s2) → {boolean}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
s1 |
string
|
string. |
s2 |
string
|
string |
Returns:
- Type:
-
boolean
true if s1 can be made equal to s2 after operations, otherwise false
(inner) countPairsOptimal(nums) → {number}
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
Returns:
- Type:
-
number
Number of pairs whose sum less than target
(inner) getAverages(nums, k) → {number}
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
k |
k
|
radius around which average needs to be calculated. |
Returns:
- Type:
-
number
List of average of k radius
(inner) maxArea(height) → {number}
Parameters:
Name | Type | Description |
---|---|---|
height |
Array.<number>
|
to define start and end of container. |
Returns:
- Type:
-
number
Maximum container area
(inner) maxSubarraySumCircular(nums) → {number}
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
Returns:
- Type:
-
number
Max subarray sum in circular array
(inner) maxTurbulenceSize(arr) → {number}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number>
|
array of numbers. |
Returns:
- Type:
-
number
Length of subarray with maximum turbulence
(inner) searchInRotatedArray(nums, target) → {number}
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
target |
number
|
element to be searched. |
Returns:
- Type:
-
number
Index of element otherwise -1
(inner) threeSum(nums) → {number}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
Returns:
- Type:
-
number
array of triplet that results in 0
(inner) threeSumClosest(nums, target) → {number}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
nums |
Array.<number>
|
array of numbers. |
target |
number
|
to which triplet should be closest. |
Returns:
- Type:
-
number
array of triplet that results in closest to target
(inner) trap(height) → {number}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
height |
Array.<number>
|
to define height at each point. |
Returns:
- Type:
-
number
Total trapped rain water