Solve several coding interview problems
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This set of problems evaluates proficiency in string processing and combinatorial parsing, arbitrary-precision arithmetic using string representations, pointer/ancestor-chain intersection detection, and computational geometry for overlap counting, emphasizing algorithmic design, correctness, and performance.
Part 1: Decode Ambiguous Morse Text
Constraints
- 0 <= len(s) <= 20
- s contains only '.' and '-'
- Use the standard Morse mapping for A-Z exactly as given
- The number of valid decodings can be exponential, so output size may dominate runtime
Examples
Input: ('.-',)
Expected Output: ['A', 'ET']
Explanation: '.-' can be decoded as A or as E followed by T.
Input: ('...',)
Expected Output: ['EEE', 'EI', 'IE', 'S']
Explanation: There are four exact segmentations using standard Morse letters.
Input: ('--',)
Expected Output: ['M', 'TT']
Explanation: '--' is either M or T + T.
Input: ('.',)
Expected Output: ['E']
Explanation: A single dot maps only to E.
Input: ('',)
Expected Output: ['']
Explanation: The empty Morse string corresponds to the empty decoded string.
Hints
- At position i, try every letter whose Morse code matches s starting at i.
- Many recursive calls solve the same suffix more than once; cache results by index.
Part 2: Subtract Large Integers Stored as Strings
Constraints
- 1 <= len(a), len(b) <= 100000
- a and b contain only characters '0' through '9'
- Inputs may contain leading zeros
- Do not convert the full strings to built-in integer types
Examples
Input: ('123', '45')
Expected Output: '78'
Explanation: 123 - 45 = 78.
Input: ('45', '123')
Expected Output: '-78'
Explanation: Since 45 < 123, the result is negative.
Input: ('1000', '1')
Expected Output: '999'
Explanation: Borrowing across zeros produces 999.
Input: ('0010', '0009')
Expected Output: '1'
Explanation: Leading zeros should not appear in the final answer.
Input: ('000', '0')
Expected Output: '0'
Explanation: Equal values normalize to '0'.
Hints
- First strip leading zeros and compare magnitudes by length, then lexicographically if lengths match.
- Implement elementary-school subtraction from right to left and track a borrow.
Part 3: Check Whether Two Family Chains Intersect
Constraints
- 0 <= number of people in parent <= 100000
- Each person has at most one parent
- The parent pointers form acyclic chains
- person1 and person2 may be None
Examples
Input: ({'A': 'B', 'B': 'C', 'D': 'C', 'C': None}, 'A', 'D')
Expected Output: True
Explanation: Both chains reach C.
Input: ({'A': 'B', 'B': None, 'C': 'D', 'D': None}, 'A', 'C')
Expected Output: False
Explanation: The two ancestor chains are disjoint.
Input: ({'A': 'B', 'B': None}, 'A', 'A')
Expected Output: True
Explanation: A chain always intersects itself.
Input: ({'A': None}, None, 'A')
Expected Output: False
Explanation: A None starting person has an empty chain.
Hints
- This is the same shape as the linked-list intersection problem.
- A two-pointer technique can align different chain lengths without extra memory.
Part 4: Find the Maximum Overlap Among Squares
Constraints
- 0 <= number of squares <= 500
- -10^9 <= x, y <= 10^9
- 0 <= length <= 10^9
- Squares are axis-aligned and boundary points count as covered
Examples
Input: ([] ,)
Expected Output: 0
Explanation: No squares means no covered point.
Input: ([(0, 0, 2)],)
Expected Output: 1
Explanation: Any point in the square is covered by exactly one square.
Input: ([(0, 0, 2), (1, 1, 2)],)
Expected Output: 2
Explanation: The overlap region [1, 2] x [1, 2] is covered by both squares.
Input: ([(0, 0, 1), (1, 0, 1)],)
Expected Output: 2
Explanation: The squares touch along the vertical edge x = 1, which counts as overlap.
Input: ([(0, 0, 2), (1, 0, 2), (1, 1, 1)],)
Expected Output: 3
Explanation: All three squares cover the point (1, 1).
Hints
- The maximum overlap can be checked at some x-coordinate that is a square's left or right edge.
- For a fixed x, reduce the problem to finding the maximum overlap among closed y-intervals, and process start events before end events at the same y.