Determine max remainders and anagram after deletions
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: In the Coding & Algorithms domain, this two-part question evaluates modular arithmetic and combinatorial reasoning for maximizing distinct array remainders and frequency-vector manipulation for determining anagram feasibility after selective character deletions, while also testing algorithm design and time/space complexity analysis.
Maximum Distinct Remainders
Constraints
- 0 <= n
- A[i] > 0 for all i
- B[i] may be any integer, so C[i] can be any value in [0, A[i]-1]
Examples
Input: ([2, 7, 11, 15],)
Expected Output: 4
Explanation: Sorted [2,7,11,15]: claim 0 (from 2), 1 (from 7), 2 (from 11), 3 (from 15) -> 4 distinct values.
Input: ([1, 1, 1],)
Expected Output: 1
Explanation: Each A[i]=1 forces C[i] in [0,0], so only value 0 is ever possible -> 1 distinct value.
Hints
- Since B[i] is free, C[i] = B[i] mod A[i] can equal any value in [0, A[i]-1]. Reframe: each index lets you pick one value from a range starting at 0.
- To maximize distinct picks, process the smaller ranges first so they grab the small values they alone can reach, leaving larger ranges for larger values.
- Sort A ascending; keep a counter cur=0; for each a, if cur < a claim value cur and increment cur. The answer is cur.
Anagram After Deleting One Letter Type From Each String
Constraints
- s and t contain only lowercase English letters
- You delete from at most one letter type in each string
- Deleting zero occurrences is allowed, so 'no deletion' is always an option
Examples
Input: ("a", "a")
Expected Output: True
Explanation: Already anagrams; delete zero of any letter.
Input: ("abc", "abc")
Expected Output: True
Explanation: Already identical frequency vectors.
Hints
- Deleting any number of one chosen letter only lets you DECREASE that single letter's count in each string; you can never increase a count.
- Compare frequency vectors. Any letter where s and t already differ must be repaired by deleting from whichever side is heavier.
- You get one deletion-letter in s and one in t. So you can repair at most one letter where s is heavier (delete in s) and at most one letter where t is heavier (delete in t). All other letters must already match.