FastPrepFind Circle Number
Problems/Find Circle Number

Find Circle Number

Oracle logoOracle● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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, student1 and student2, 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.

Function

findCircleNum(queryType: String[], student1: int[], student2: int[]) → int

Complete the function findCircleNum in the editor.

findCircleNum has the following parameters:

  1. 1. String[] queryType: an array of strings representing the type of query
  2. 2. int[] student1: an array of integers representing the first student IDs
  3. 3. int[] student2: an array of integers representing the second student IDs

Returns int: the sum of the sizes of each group of friends for the two students in a Total query

Examples

Example 1

queryType = ["Friend", "Friend", "Total"]student1 = [1, 2, 1]student2 = [2, 3, 4]return = 4

The queries are assembled, aligned by index:

Index queryType student1 student2

0 Friend 1 2

1 Friend 2 3

2 Total 1 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 2 is indirectly part of the circle of friends of student 1.

Constraints

  • ૮ ․ ․ ྀིა

More Oracle interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Unreachable WarehousesVisa · OAVisa interview questions
  • Minimum Contiguous ReplacementsAmazon · OA
  • Connected Components with Divisor ThresholdInMobi · OAInMobi interview questions
  • Doctor Appointment Slot AssignmentDRW · OADRW interview questions
  • Visible Profiles CountMicrosoft · OAMicrosoft interview questions
  • TikTok Server Network OptimizationTikTok · OATikTok interview questions
  • Get Node To RemoveSalesforce · OASalesforce interview questions
  • Happy NeighbourhoodHackerEarth · OA
  • Longest Contiguous Houses After Each BuildZipRecruiter · OAZipRecruiter interview questions
  • Number of Good PairsCommvault · OACommvault interview questions

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int findCircleNum(String[] queryType, int[] student1, int[] student2) {
      // write your code here
    }

}
Checking account…