Solve four coding problems
Company: Nebius
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This set of problems evaluates algorithmic problem-solving skills focused on array and string manipulation, frequency and multiset reasoning, sliding-window and coverage concepts, and combinatorial counting for palindromability.
Part 1: Longest All-Healthy Service Streak
Constraints
- 0 <= len(results) <= 100000
- If `results` is non-empty, each day contains the same number of services and at least 1 service
- Each value is either 0 or 1
Examples
Input: ([[1,1,1],[1,1,1],[1,0,1],[1,1,1],[1,1,1],[1,1,1]],)
Expected Output: 3
Explanation: The first two days are healthy, the third day breaks the streak, and the last three days form the longest healthy streak.
Input: ([[1,0],[0,1]],)
Expected Output: 0
Explanation: No day has all services passing.
Input: ([],)
Expected Output: 0
Explanation: With no days, there is no healthy streak.
Input: ([[1,1,1]],)
Expected Output: 1
Explanation: The single day is healthy.
Hints
- First decide for each day whether it is healthy or not.
- Then scan the days and track the longest consecutive run of healthy ones.
Part 2: Shortest Substring Covering All Distinct Characters
Constraints
- 0 <= len(s) <= 200000
- Characters may repeat arbitrarily
- The solution should be efficient for long strings
Examples
Input: ("aabcbcdbca",)
Expected Output: 4
Explanation: The distinct characters are a, b, c, and d. The shortest substring containing all of them is "dbca".
Input: ("aaaa",)
Expected Output: 1
Explanation: There is only one distinct character, so any single 'a' works.
Input: ("",)
Expected Output: 0
Explanation: An empty string has no required characters.
Input: ("abca",)
Expected Output: 3
Explanation: The distinct characters are a, b, and c. "abc" or "bca" has length 3.
Input: ("abcdef",)
Expected Output: 6
Explanation: Every character is distinct, so the whole string is required.
Hints
- Count how many unique characters exist in the whole string first.
- A sliding window can expand to satisfy the requirement and shrink to find the minimum length.
Part 3: Minimize Remaining Product Types After Deletions
Constraints
- 0 <= len(product_ids) <= 200000
- 0 <= m <= len(product_ids)
- Product IDs are integers
Examples
Input: ([1,1,1,2,2,3], 3)
Expected Output: 1
Explanation: Delete product 3 once and product 2 twice. Only product 1 remains.
Input: ([4,3,1,1,3,3,2], 3)
Expected Output: 2
Explanation: The best choice is to remove the two IDs with frequency 1, then one extra deletion cannot remove another ID completely.
Input: ([], 0)
Expected Output: 0
Explanation: There are no products to begin with.
Input: ([5,5,5], 0)
Expected Output: 1
Explanation: No deletions are made, so the one existing product type remains.
Input: ([1,2,3], 3)
Expected Output: 0
Explanation: All products can be deleted.
Hints
- A distinct ID disappears only when all of its occurrences are deleted.
- To remove the most distinct IDs, eliminate the IDs with the smallest frequencies first.
Part 4: Count String Pairs That Can Form a Palindrome
Constraints
- 0 <= len(words) <= 200000
- 0 <= sum(len(word) for word in words) <= 200000
- Each string contains only lowercase English letters 'a' to 'z'
Examples
Input: (["abc","cba","xy","yx"],)
Expected Output: 2
Explanation: The valid pairs are ("abc", "cba") and ("xy", "yx").
Input: (["a","","bb","ab"],)
Expected Output: 4
Explanation: The valid pairs are ("a", ""), ("a", "bb"), ("a", "ab"), and ("", "bb").
Input: ([],)
Expected Output: 0
Explanation: There are no pairs in an empty list.
Input: (["abc","def"],)
Expected Output: 0
Explanation: The combined characters of the only pair have too many odd counts to form a palindrome.
Input: (["a","b","c","ab"],)
Expected Output: 2
Explanation: The valid pairs are ("a", "ab") and ("b", "ab").
Hints
- A multiset of characters can be rearranged into a palindrome if at most one character has an odd count.
- For each string, track only which letters have odd frequency, using a bitmask.