This is a verified interview question from Intuit. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Bash: Array Sum" covers key patterns like Other.
"Given an array of strings, add all the numeric values within the array and print the sum to stdout. If there are no numeric values, print 0. Note: The sum will not exceed 7,000,000. ### Example: my_array = ["First", "2", "third", "4"] The array_sum function should return 6 because 2 + 4 = 6. ### Input Format For Custom Testing The input contains the newline-separated elements of the given array. ### Sample Case 0 Sample Input For Custom Testing Abc 20 Efg231 10 cDe Sample Output 30 ### Explanation The numerical elements are 20 and 10 that sum to 30. ### Sample Case 1 Sample Input For Custom Testing SingleWord Sample Output 0 ### Explanation No numeric elements are present in the array. Note: In platform you have to code in Bash !/usr/bin/env bash // Input array is read and stored into my_array variable. // You can view the code by pressing > button above. function array_sum() { typeset -a data=("$@") # Write your code here } array_sum "${my_array[@]}""
Join thousands of developers practicing for Intuit.