Sum of absolute values of integers in a list

This problem asks for the sum of the absolute values of a given list of integers. For example, given the list [2, -4, 6, -8], the sum of the absolute values would be 20.


Given a list of integers, return the sum of the absolute values of the integers.
Example input: [2, -4, 6, -8]
Example output: 20


This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def sum_abs(lst):
    return sum(map(abs, lst))

# This solution is optimal because it uses the built-in sum function, which is O(n) and the built-in map function, which is also O(n).
# The abs function is also O(1) so the overall complexity is O(n).

A.I. Evaluation of the Solution

This solution is correct and demonstrates a good understanding of time complexity.

Evaluated at: 2022-11-22 12:16:37