leetle

Daily challenge for 2026-10-19

657. Count Mutual Pen Pals

You are given a dictionary pen_pals where each key is a person's name and the value is the name of the person they nominated as their pen pal. A mutual pen pal pair is formed when two different people nominate each other. Return the total number of unique mutual pen pal pairs.

Constraints:
There are 0–1,000 dictionary entries. Each person has at most one nomination. Names are non-empty case-sensitive ASCII strings. A nominee need not be a dictionary key, and self-nominations never form a pair.

Example:
Input: pen_pals = {"Alice": "Bob", "Bob": "Alice", "Charlie": "Dave", "Dave": "Eve", "Eve": "Dave"}
Output: 2

Run this challenge interactively in Python or JavaScript when the app loads.