We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This function takes an array of non-negative integers (numbers) and its size (n) as parameters.
It initializes an array count to count the frequency of each digit from 0 to 9.
It then iterates through each number in the array, updating the digit frequencies.
After counting, it calculates the sum of digits weighted by their frequencies.
It returns "Yes" if the sum is divisible by 3, indicating that a new integer can be constructed, and "No" otherwise.
main Function:
It starts by inputting the number of queries (q).
For each query, it takes the number of non-negative integers (n) and the integers themselves.
It calls the canConstruct function for each set of numbers and prints the result.
The program checks if it's possible to construct a new integer from each set of non-negative integers such that the resulting number is divisible by 3. The result for each query is printed.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Constructing a Number
You are viewing a single comment's thread. Return to all comments →
canConstruct Function:
This function takes an array of non-negative integers (numbers) and its size (n) as parameters. It initializes an array count to count the frequency of each digit from 0 to 9. It then iterates through each number in the array, updating the digit frequencies. After counting, it calculates the sum of digits weighted by their frequencies. It returns "Yes" if the sum is divisible by 3, indicating that a new integer can be constructed, and "No" otherwise. main Function:
It starts by inputting the number of queries (q). For each query, it takes the number of non-negative integers (n) and the integers themselves. It calls the canConstruct function for each set of numbers and prints the result. The program checks if it's possible to construct a new integer from each set of non-negative integers such that the resulting number is divisible by 3. The result for each query is printed.