Get Sizes of Friends Groups 🥗
Updated
Problem statement
As new students begin to arrive at college, each receives a unique ID number, 1 to n. Initially, the students do not know one another, and each has a different circle of friends. As the semester progresses, other groups of friends begin to form randomly.
There will be three arrays, each aligned by an index. The first array will contain a queryType which will be either Friend or Total. The next two arrays, students1 and students2, will each contain a student ID. If the query type is Friend, the two students become friends. If the query type is Total, report the sum of the sizes of each group of friends for the two students.
Complete the function getSizesOfFriendsGroups in the editor.
getSizesOfFriendsGroups has the following parameters:
- 1.
String[] queryType: an array of strings representing the type of query - 2.
int[] student1: an array of integers representing the first student IDs - 3.
int[] student2: an array of integers representing the second student IDs - 4.
n: the number of students
int: the sum of the sizes of each group of friends for the two students in a Total query
Function
getSizesOfFriendsGroups(queryType: String[], student1: int[], student2: int[], n: int) → intExamples
Example 1
queryType = ["Friend", "Friend", "Total"]student1 = [1, 2, 1]student2 = [2, 3, 4]n = 4return = 4
Students will start as discrete groups {1}, {2}, {3} and {4}. Students 1 and 2 become friends with the first query, as well as students 2 and 3 in the second. The new groups are {1, 2}, {2, 3} and {4} which simplifies to {1, 2, 3} and {4}. In the third query, the number of friends for student 1 = 3 and student 4 = 1 for a Total = 4. Notice that student 3 is indirectly part of the circle of friends of student 1 because of student 2.
Constraints
Unknown for now 🍱
More DoorDash interview questions
- Customer Bootstrap APIPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Warehouse Order PrioritizationPHONE SCREEN · Seen Nov 2026
- Random Dasher Set OperationsONSITE INTERVIEW · Seen Nov 2026
- Dasher Pay with Store Waits and Peak HoursPHONE SCREEN · Seen Nov 2026
- Team FormationOA · Seen Oct 2026
- Simulate an Idempotent Refund Service FlowONSITE INTERVIEW · Seen Sep 2026
- Dasher Active TimePHONE SCREEN · Seen Sep 2026
- First Unique ID in a StreamONSITE INTERVIEW · Seen Aug 2026
- Minimum Parenthesis Removals and Their IndicesONSITE INTERVIEW · Seen Aug 2026
- Minimum Processing Speed with Multiple RidersONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Connected GroupsVisa · OAVisa interview questions
- Maximum DifferenceAkuna Capital · OAAkuna Capital interview questions
- Visible Profiles CountIBM · OAIBM interview questions
- Disaster RecoveryHeadlands Technologies · OAHeadlands Technologies interview questions
- Minimum Cost to Supply Water with Wells and PipesInfosys · OAInfosys interview questions
- Recoverable Elements from Range-Sum MeasurementsEthos Life · OA
- Minimum Contiguous ReplacementsAmazon · OA
- Connected Components with Divisor ThresholdInMobi · OAInMobi interview questions
- Doctor Appointment Slot AssignmentDRW · OADRW interview questions
- Biggest Connected ComponentCodeium · OACodeium interview questions
DoorDash interview experiences
- DoorDash SWE Onsite: Donation System Design: 1 Experience
- DoorDash SWE Phone Screen: Bootstrap API in Java: 1 Experience
- DoorDash SWE Virtual Onsite: 1 Experience
- DoorDash SWE Phone Screen: Bootstrap API Parsing: 1 Experience
- DoorDash Senior SWE Onsite Interview Experience: 1 Experience
- DoorDash AI CodeCraft Interview: 8 Experiences