Interview begins with "Introduce yourself"
Question 1:
Given a string, you have to return the first word in the string having the most number of repeating characters.
Example:
"Today is the greatest day ever!"
Answer:
"greatest."
Both "greatest" and "ever" have the same number of repeating characters, at a maximum of 2 (e's & t's in "greatest" and 2 e's in "ever").
However, "greatest" occurs first, so "greatest" will be the answer.
Approach:
To obtain each specific word in the string, you can traverse by segmenting words on punctuation. I used stringstream in C++.
Then, I used a map for each word to track the frequency of characters, then have a global maximum variable and a string called the result word.
Normal traversal over stringstream and hashing to get the first word in the string having the most number of repeating characters.
Overall Approach: StringStream + hashing.
Time complexity: O(n*m)
Space Complexity: O(m)
Where n is the length of the string, and m is the length of the largest word in the string.
I accomplished all this in 10-15 minutes.
Question 2:
Given an array, return true or false.
Condition:
True -> If there exists a combination that sums to the maximum element in the array without using the maximum element.
False -> Otherwise.
Example: [1,3,4,5,12]
Answer: True.
(3,4,5 -> 12)
This problem is similar to the Target Sum problem on LeetCode with a modification.
Approach:
Get the maximum element in the array and form a new array/vector without the maximum element. After this, apply a recursive approach to
find the subsequence with the target sum.
Overall Approach: Find the maximum + get the new vector without the maximum + Recursion + dynamic programming (target*n).
Time Complexity: O(n*maximum_element)
Space Complexity: O(n*maximum_element)Amazon OA

BNY Mellon
Interested people can join for updates on
leetcode daily problem and contest discussion : group