2695. Array Wrapper LeetCode Solution
In this guide, you will get 2695. Array Wrapper LeetCode Solution with the best time and space complexity. The solution to Array Wrapper problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Array Wrapper solution in C++
- Array Wrapper solution in Java
- Array Wrapper solution in Python
- Additional Resources

Problem Statement of Array Wrapper
Create a class ArrayWrapper that accepts an array of integers in its constructor. This class should have two features:
When two instances of this class are added together with the + operator, the resulting value is the sum of all the elements in both arrays.
When the String() function is called on the instance, it will return a comma separated string surrounded by brackets. For example, [1,2,3].
Example 1:
Input: nums = [[1,2],[3,4]], operation = “Add”
Output: 10
Explanation:
const obj1 = new ArrayWrapper([1,2]);
const obj2 = new ArrayWrapper([3,4]);
obj1 + obj2; // 10
Example 2:
Input: nums = [[23,98,42,70]], operation = “String”
Output: “[23,98,42,70]”
Explanation:
const obj = new ArrayWrapper([23,98,42,70]);
String(obj); // “[23,98,42,70]”
Example 3:
Input: nums = [[],[]], operation = “Add”
Output: 0
Explanation:
const obj1 = new ArrayWrapper([]);
const obj2 = new ArrayWrapper([]);
obj1 + obj2; // 0
Constraints:
0 <= nums.length <= 1000
0 <= nums[i] <= 1000
Note: nums is the array passed to the constructor
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
2695. Array Wrapper LeetCode Solution in C++
class ArrayWrapper {
private nums: number[];
constructor(nums: number[]) {
this.nums = nums;
}
valueOf(): number {
return this.nums.reduce((sum, num) => sum + num, 0);
}
toString(): string {
return '[' + this.nums.join(',') + ']';
}
}
/* code provided by PROGIEZ */
2695. Array Wrapper LeetCode Solution in Java
N/A
// code provided by PROGIEZ
2695. Array Wrapper LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.