
Asked in OPERA
Game of 3 Problem Statement
Help the Ultimate Ninja Ankush form groups of integers such that the sum of each group is divisible by 3. Given an array of integers, count how many groups of sizes 2 and 3 can be created where the sum of the group elements is a multiple of 3.
Input:
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a single integer, ‘N,’ specifying the number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers, representing the array elements.
Output:
For each test case, return an integer denoting the total number of groups that can be formed.
Example:
Input:
N = 5, ARR = [1, 2, 3, 4, 5]
Output:
8
Explanation:
The valid pairs are: (1,3), (1,2), (1,5), (2,4), (4,5), (1,2,3), (3,4,5), and (1,3,5).
Constraints:
- 1 <= ‘T’ <= 10
- 1 <= ‘N’ <= 5000
- 0 <= ‘ARR[i]’ <= 104
- Time Limit: 1 sec
Note:
Focus on implementing the function returning the expected result as outputs are pre-handled.

AnswerBot
4mo
The task is to form groups of integers from an array where the sum of each group is divisible by 3. Count the number of valid groups of sizes 2 and 3.
Iterate through the array and check for pairs and ...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for OPERA Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

