Mean of Three Numbers Stored as Linked Lists
Updated
Problem statement
Each of a, b and c is a linked list that spells out a non-negative whole number, one digit per node, read from the head. For example, 4 → 5 → 6 means 456.
Return the mean of the three numbers, (a + b + c) / 3 rounded down, as a linked list in the same form. The answer has no leading zeros, except that the number 0 is a single node 0.
Function
meanOfThree(a: ListNode, b: ListNode, c: ListNode) → ListNodeExamples
Example 1
a = [4,5,6]b = [7,8]c = [9,9,9]return = [5,1,1]The numbers are 456, 78 and 999. Their sum is 1533, and 1533 / 3 = 511 exactly, so the answer is 5 → 1 → 1.
Example 2
a = [1]b = [0]c = [0]return = [0]The sum is 1. One third of 1 rounds down to 0, so the answer is a single node 0.
Example 3
a = [9,9,9,9,9]b = [9,9,9,9,9]c = [2]return = [6,6,6,6,6]99999 + 99999 + 2 = 200000. Dividing by 3 gives 66666 with 2 left over, which is dropped, so the answer is five nodes of 6.
Constraints
- Each list has between
1and1000nodes. 0 <= Node.val <= 9- No list has a leading zero, except a list that is the single node
0.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEW
- First-Fit Memory AllocatorGoogle · ONSITE INTERVIEW
- Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEW
- Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEW
- LRU CacheAMD · ONSITE INTERVIEW
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEW
- Least Recently Used CacheByteDance · PHONE SCREEN · ONSITE INTERVIEW
- Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Expected Value of Modified DiceJane Street · ONSITE INTERVIEW