You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Product of array except self: [JavaScript](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/productExceptSelf/productExceptSelf.js)[Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/productExceptSelf/productExceptSelf.md)
40
40
41
41
3. Max sum subarray: [JavaScript](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/maxSubArray.js)
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.
3
+
4
+
## Examples:
5
+
Example 1:
6
+
7
+
Input: nums = [1,1,1,3,3,4,3,2,4,2]
8
+
Output: true
9
+
10
+
Example 2:
11
+
12
+
Input: nums = [1,2,3,4, 5]
13
+
Output: false
14
+
15
+
**Algorithmic Steps(Approach 1&2)**
16
+
This problem is solved with an optimal solution using either set or map to find out duplicate elements exists or not. The algorithmic approach can be summarized as follows:
17
+
18
+
1. Create an empty set or map to store the elements.
19
+
20
+
2. Iterate an input array using for-each loop.
21
+
22
+
3. If the current element appears in a set or map, return `true` immediately to indicate duplicate elements exist.
23
+
24
+
4. Otherwise add the current element to the set or map.
25
+
26
+
5. After the for loop, return `false` to indicate there are no duplicate elements exist in the array.
27
+
28
+
29
+
**Time and Space complexity:**
30
+
This algorithm has a time complexity of O(n), where n is the number of elements in an array. This is because we are traversing the array at most once.
31
+
32
+
Here, we use any additional datastructure like set or map. Hence, the space complexity will be O(n).
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.
3
+
4
+
## Examples:
5
+
Example 1:
6
+
7
+
Input: nums = [1,1,1,3,3,4,3,2,4,2]
8
+
Output: true
9
+
10
+
Example 2:
11
+
12
+
Input: nums = [1,2,3,4, 5]
13
+
Output: false
14
+
15
+
**Algorithmic Steps(Approach 1&2)**
16
+
This problem is solved with an optimal solution using either set or object to find out duplicate elements exists or not. The algorithmic approach can be summarized as follows:
17
+
18
+
1. Create an empty set or an object to store the elements.
19
+
20
+
2. Iterate an input array using for-each loop.
21
+
22
+
3. If the current element appears in a set or an object, return `true` immediately to indicate duplicate elements exist.
23
+
24
+
4. Otherwise add the current element to the set or an object.
25
+
26
+
5. After the for loop, return `false` to indicate there are no duplicate elements exist in the array.
27
+
28
+
29
+
**Time and Space complexity:**
30
+
This algorithm has a time complexity of O(n), where n is the number of elements in an array. This is because we are traversing the array at most once.
31
+
32
+
Here, we use any additional datastructure like set or object. Hence, the space complexity will be O(n).
0 commit comments