FastPrepShared Interest
Problems/Shared Interest

Shared Interest

InMobi logoInMobi● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi full-time online assessment. Our version is about 99% the same as the reported assessment prompt.

There are friendsNodes friends, numbered from 1 through friendsNodes. Relationship i joins friends friendsFrom[i] and friendsTo[i], and it has an integer interest label friendsWeight[i].

Sharing an interest is transitive. If friends A and B share an interest, and B and C share it too, then A and C also share it. So pick one interest label and keep only the relationships with that label. Two friends share that interest when a chain of these relationships links them, either directly or through other friends.

For each pair of two different friends, count how many different interest labels they share. The order inside a pair does not matter. Look at the pairs with the highest count. Among them, return the largest product of the two friend numbers.

Function

maxShared(friendsNodes: int, friendsFrom: int[], friendsTo: int[], friendsWeight: int[]) → int

Examples

Example 1

friendsNodes = 4friendsFrom = [1,1,2,2,2]friendsTo = [2,2,3,3,4]friendsWeight = [2,3,1,3,4]return = 6

Pairs (1, 2) and (2, 3) each share two interests. Their products are 2 and 6, so the answer is 6.

Example 2

friendsNodes = 5friendsFrom = [1,2,3,1,2]friendsTo = [2,3,4,3,4]friendsWeight = [7,7,7,9,9]return = 8

Interest 7 connects friends 1 through 4. Interest 9 additionally connects pairs (1, 3) and (2, 4). Those two pairs share the maximum of two interests, and 2 * 4 = 8 is the larger product.

Example 3

friendsNodes = 6friendsFrom = [1,2,3,4,5]friendsTo = [2,3,4,5,6]friendsWeight = [1,1,1,1,1]return = 30

All six friends are connected by interest 1, so every pair ties with one shared interest. The largest product is 5 * 6 = 30.

Constraints

  • 2 <= friendsNodes <= 100
  • 1 <= friendsFrom.length <= min(200, friendsNodes * (friendsNodes - 1) / 2)
  • friendsFrom.length == friendsTo.length == friendsWeight.length
  • 1 <= friendsFrom[i], friendsTo[i] <= friendsNodes
  • friendsFrom[i] != friendsTo[i]
  • 1 <= friendsWeight[i] <= 100
  • The same pair may appear with different interest labels. Each distinct label is counted at most once for a pair.

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Delivery ServiceOA · Seen Jun 2026
  • Temporal AnomaliesOA · Seen Jun 2026

Similar questions at other companies

  • Minimum Unreachable WarehousesVisa · OAVisa 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
  • Number of Good PairsCommvault · OACommvault interview questions
  • Process Queries to Find Critical NodesCisco · OACisco interview questions
  • Malware SpreadFlexport · OAFlexport interview questions
  • Count Distinct Word MeaningsDuolingo · OADuolingo interview questions
  • Team TournamentNutanix · OANutanix interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public int maxShared(int friendsNodes, int[] friendsFrom, int[] friendsTo, int[] friendsWeight) {
        // write your code here.
    }
}
Checking account…