FastPrepNonzero Totals by Name
Problems/Nonzero Totals by Name

Nonzero Totals by Name

EPAM logoEPAM● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says the candidate got a list of pairs, each a string and an integer. They had to read the input, add up the integers for each string, and print the strings whose final sums were not zero. Its example input Suresh 10, Suresh 20, Aditya 20, Aditya -20 prints Suresh 30.

The report does not say in what order to print the names, whether letter case matters, or how large the numbers can be. Here, names come out in the order they first appear, and letter case matters. You get the pairs as two arrays and return the printed lines as strings instead of reading input and printing.

Our version is about 90% the same as the reported question.

You are given a list of pairs. Each pair holds a name and an integer. The pairs come as two arrays of the same length, names and values: pair i is names[i] together with values[i].

Add up the integers that belong to each name. Then return one line for every name whose final sum is not zero, and leave out every name whose sum is zero. Each line is the name, one space, and the sum, such as "Suresh 30". Write the sum as a plain integer, with a minus sign when it is negative.

Put the lines in the order in which the names first appear in names. Names are case-sensitive, so "Sam" and "sam" are different names. If every sum is zero, return an empty array.

Function

nonZeroTotals(names: String[], values: int[]) → String[]

Examples

Example 1

names = ["Suresh","Suresh","Aditya","Aditya"]values = [10,20,20,-20]return = ["Suresh 30"]

Suresh's sum is 10 + 20 = 30. Aditya's sum is 20 + (-20) = 0, so Aditya is left out.

Example 2

names = ["Asha","Bilal","Asha","Chen","Bilal","Dev"]values = [4,-3,6,0,3,-9]return = ["Asha 10","Dev -9"]

Asha's sum is 4 + 6 = 10 and Dev's sum is -9. Bilal's sum is -3 + 3 = 0 and Chen's sum is 0, so both are left out. Asha appears before Dev, so her line comes first.

Example 3

names = ["Sam","sam","Sam"]values = [7,2,-7]return = ["sam 2"]

Letter case matters, so "Sam" and "sam" are different names. Sam's sum is 7 + (-7) = 0, and sam's sum is 2.

Constraints

  • 1 <= names.length <= 10^4
  • values.length == names.length
  • 1 <= names[i].length <= 20
  • names[i] contains only English letters (a-z and A-Z).
  • -10^9 <= values[i] <= 10^9

More EPAM interview questions

  • Rob Houses Without Getting CaughtOA · Seen Jul 2024
  • Detect a Loop in a Linked ListONSITE INTERVIEW · Seen Oct 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Oct 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Container With Most WaterPHONE SCREEN · Seen Oct 2026
  • Convert an Entry List to a MapPHONE SCREEN · Seen Oct 2026
  • Count Array Element FrequenciesPHONE SCREEN · Seen Oct 2026
  • Find First and Last Position of Element in Sorted ArrayPHONE SCREEN · Seen Oct 2026
  • Group AnagramsPHONE SCREEN · Seen Oct 2026
  • Longest Consecutive SequencePHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Customer Signer ScreeningState Farm · OA
  • String-Pair Frequency SimilarityIBM · OAIBM interview questions
  • Number-Character Bijective MappingAdobe · OAAdobe interview questions
  • Unique Difference PatternMicrosoft · OAMicrosoft interview questions
  • Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
  • Palindrome-Rearrangeable PairsExpedia · OAExpedia interview questions
  • Count Sales Rung Up at the Wrong PriceDocuSign · OADocuSign interview questions
All EPAM interview questionsSee EPAM hiring insights
Saved
class Solution {
    public String[] nonZeroTotals(String[] names, int[] values) {
        // Write your code here.
    }
}
Checking account…