# CSPT19 Lecture 2
## [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)
```
class Solution:
"""
Understand
[[1,2,3],
[3,2,1]]
output: 6
[[1,2,3]]
output: 6
[[1,2,3],
[3,2,100]]
output: 105
Plan
Go through each customer and find the max wealth seen so far
"""
def maximumWealth(self, accounts: List[List[int]]) -> int:
maxWealth = 0
for customer in accounts:
customerWealth = sum(customer)
if customerWealth > maxWealth:
maxWealth = customerWealth
return maxWealth
```
## [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/)
```
class Solution:
"""
Understand
nums = [1,2,3,1,1,3]
output: 4
nums = [1,2,3]
output: 0
nums = [0,0,0,0]
output: 6
nums = []
output: 0
Plan
Keep track of numGoodPairs
We can iterate through all possible pairs (using two for-loops).
If a pair is a valid "good pair" then increment numGoodPairs
return numGoodPairs
"""
def numIdenticalPairs(self, nums: List[int]) -> int:
numGoodPairs = 0
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] == nums[j]:
numGoodPairs += 1
return numGoodPairs
```
## [N-Repeated Element in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array/)
```
class Solution:
"""
Understand
[1,2,3,3] length = 4, N = 2
output = 3
[6,1,6,5,6,1] length = 6, N = 3
output = 6
Plan
Go through entire list and keep track of how many times each
element occurs using a dictionary (element -> numTimesOccurence)
We iterate through the dictionary again and return the number that occurred
N times
"""
def repeatedNTimes(self, A: List[int]) -> int:
counts = {}
for num in A:
if num not in counts:
counts[num] = 1
else:
counts[num] += 1
target = len(A) / 2
for (num, timesAppeared) in counts.items():
if timesAppeared == target:
return num
```