समस्या
Build a running sum: the value at position i is the sum of all numbers from position 0 through i.
Implement running_sum(numbers).
Input
numbers: The list of integers.
Output
Return the list of running totals.
सीमाएँ
0 ≤ length ≤ 100,000; totals fit in a 64-bit integer
उदाहरण
इनपुट:
numbers = [1, 2, 3, 4]
अपेक्षित आउटपुट:
expected = [1, 3, 6, 10]
इनपुट:
std::vector<long long> numbers = {1, 2, 3, 4};
अपेक्षित आउटपुट:
std::vector<long long> expected = {1, 3, 6, 10};
इनपुट:
long[] numbers = new long[] {1, 2, 3, 4};
अपेक्षित आउटपुट:
long[] expected = new long[] {1, 3, 6, 10};
व्याख्या
Totals so far: 1, 1+2=3, 3+3=6, 6+4=10.
इनपुट:
numbers = [5, -5, 5]
अपेक्षित आउटपुट:
expected = [5, 0, 5]
इनपुट:
std::vector<long long> numbers = {5, -5, 5};
अपेक्षित आउटपुट:
std::vector<long long> expected = {5, 0, 5};
इनपुट:
long[] numbers = new long[] {5, -5, 5};
अपेक्षित आउटपुट:
long[] expected = new long[] {5, 0, 5};
व्याख्या
Totals: 5, 0, 5.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Har output element pichhle sab elements aur khud ke total par depend karta hai.
संकेत 2
List ke through jaate hue cumulative total maintain karo.
संकेत 3
First position ko simply first input value hi dikhana chahiye.
अपेक्षित जटिलता
समय O(n), अतिरिक्त स्थान O(n)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।