Week 10: Assorted Problems
1) Two Out of Three
Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order. Only values between 1 and 100 will be present.
Input: nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
Output: [3,2]
Input: nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]
Output: [2,3,1]
Input: nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]
Output: []
Time Complexity: O(n)
Space Complexity: O(n)
2) Middle Index in Array
Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).
A middleIndex is an index where nums[0] + nums[1] + … + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + … + nums[nums.length-1].
If middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.
Return the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.
Input: nums = [2,3,-1,8,4]
Output: 3
Explanation:
The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
The sum of the numbers after index 3 is: 4 = 4
Input: nums = [1,-1,4]
Output: 2
Explanation:
The sum of the numbers before index 2 is: 1 + -1 = 0
The sum of the numbers after index 2 is: 0
Input: nums = [2,5]
Output: -1
Explanation:
There is no valid middleIndex.
Input: nums = [1]
Output: 0
Explantion:
The sum of the numbers before index 0 is: 0
The sum of the numbers after index 0 is: 0
Time Complexity: O(n)
Space Complexity:n O(1)
ICPC 2026 Questions
1) D2 Cowtrain
Nick claims his keyboard has been hacked reconfiguring the key mappings. Given two strings str1 being what Nick was trying to send, str2 is what was actually sent. Return whether or not Nick’s keyboard was truely hacked.
Nick’s keyboard is hacked if the following two conditions are met:
- No two keys map to the same character
- Keys do not change their mapping
Input: str1 = cal, str2 = cow
Output: True
Explanation:
a -> o
l -> w
Input: str1 = caltrain, str2 = cowtrain
Output: False
Explanation:
a -> o
l -> w
a -> a (key 'a' typed both 'o' and 'a')
Constraints:
str1andstr2consists of only lowercase letters- Length of
str1== length ofstr2 str2is a different string thanstr1
2) D1 Cable Management
Given a list of (x, y) coordinates centers representing the locations of data centers. Return the minimum of cables to connect every data center.
Data centers are connected if there is at least one cable connecting from one data center to another. Cables are infinite-length axis-aligned lines.
Input:
centers = [
[1, 1],
[1, 2],
[2, 1],
[2, 2]
]
Output: 3
Explanation:
2 wires to connect across x-axes or y-axes
1 wire on opposite axis to connect the paired data centers.
Example:
Connect (1,1), (1,2) and (2,1), (2,2) with two y-axis cables.
Connect the y-axis cables with one x-acis cable.
Input:
centers = [
[6, 1],
[6, 2],
[1, 7],
[2, 7]
]
Output: 2
Explanation:
Pairing closest data centers together will have two opposite axes cables connect at (6, 7)