Expedia OA

已挂

3 Problems, 90 minutes.

Problem 1

Adding sequence number to the end of the repeating names.

Input

[“tom”,“alex”,“jack”,“Alex”]

Ouput

[“tom”,“alex”,'jack",“alex1”]

Explanation

Name “alex” apears twice, the first one can be ignored, sequence number should be added from the second alex.

Solution

Count as you go in a HashMap and ignore the first index 0.

Problem 2

没找到原题。HankerRank上的,题目叫Selling Products。

Take out the given number of elements in the list so that the uniqueness is low.

Input

ids = [1,2,3,1,2,2] m=3

Output

1

Explanation

We can remove 3, 1, 1 and leave only 2 from the input array. Where 1 represents the number of unique number left in the list. In this case, it is 1.

Solution

  1. Create a class Item with property count and id. id here is the number from the input array.

  2. Count all the unique elements via a HashMap, once it is done output them in a List. Sort it in desending order.

  3. From the end, decrease the count while m–. When count is 0, remove it from the list.

  4. Return the size of the list.

Problem 3

Looks like a problem similar as word sequence which requires dynamic programing knowledge.

Expedia OA 90min

90mins,一共12道题,其中2道算法题,其他是 选择题,算法题很简单,选择题倒是有的没怎么见过。
算法1:给一个list of string,再给一个list of range,让找在给的range中以元音开头和结尾的string的个数。
例子:input: [aba, acd, ii, eje], [[1-2], [2-4]], output: [1, 2]
算法2:给一个palindrome,替换其中一个字母把它变成一个非palindrome,并且这个新单词在字母顺序上要比原单词小而且是最小的,如果变不了就返回impossible。
例子:input: [bab], output: [aab]; input[aaa], output: impossible