← 返回 rippling 的题目列表Data Processing and Bug Fixing Task
类型:online_judge
Given an array of integers, implement a function to calculate the sum of all elements in the array. The task consists of the following three parts:
Part 1
Implement a function calculate_sum(arr: List[int]) -> int, which takes an array of integers as input and returns the sum of all elements.
Part 2
Write test cases for the above function to ensure it works correctly for various inputs. Test cases should cover positive numbers, negative numbers, and empty array scenarios.
Part 3
Extend the function to exclude duplicate elements' contribution when calculating the total sum. For example, for array [1, 2, 2, 3], it should return 6 instead of 8.
Example
Input
[1, 2, 3]