quora 的oa,还是老题目,篮球队成员组group,但是test case 及其诡异。按常规方法一半都通过不了,tle, 最后挂了,服。
python写的。
补充一个
Overview
- Online test with CodeSignal.
- Record the webcam and desktop.
- Need to provide ID to prove you are the same person.
- This test will take 70 minutes.
- Score will show immediately when finished the test.
goodTuples
Give an array and find the count of a pair number and a single number combination in a row of this array. Target array is a[i - 1], a[i], a[i + 1]
Input: a = [1, 1, 2, 1, 5, 3, 2, 3]
Output: 3
Explain:
[1, 1, 2] -> two 1 and one 2(O)
[1, 2, 1] -> two 1 and one 2(O)
[2, 1, 5] -> one 2, one 1 and one five(X)
[1, 5, 3] -> (X)
[5, 3, 2] -> (X)
[3, 2, 3] -> (O)
Time: O(n)
divisorSubstrings
Give a number n
and digit number k
find all serial substring is able to divisible n.
Input: n = 120, k = 2
Output: 2
Explain:
120 -> 12 and 20
120 % 12 == 0 (O)
120 % 20 == 0 (O)
Input: n = 555, k = 1;
Output: 1
Explain:
555 -> 5, 5 and 5 (Duplicate so only count one 5)
555 % 5 == 0 (O)
Input: n = 2345, k = 2
Output: 0
Explain:
2345 -> 23, 34, 45
2345 % 23 != 0 (X)
2345 % 34 != 0 (X)
2345 % 45 != 0 (X)
Time: O(n)
constructorNames
Give two String a
and b
find the is there any possible to repalce the same frequency character
Input: a = babczzz, b = abbzccc
Output: true
Explain:
In a string,
a -> 1, b -> 2, c-> 1, z -> 3
In b string,
a -> 1, b -> 2, c -> 3, z -> 1
a and b are the same frequency.
c and z have same frequency so they can replace to each other.
So return true.
Input: a = x, b = y
Output: false
Explain: Not the same character
Input: a = ii, b = j
Output: false
Explain: length is different.
Time: Unknow, I didn’t solve it. But I assume it will be O(n).
coolFeature
Give three array a
, b
and query
. This one is hard to explain. Just read the example.
Input:
a = [1, 2, 3]
b = [3, 4]
query = [[1, 5], [1, 1 , 1], [1, 5]]
Output:
[2, 1]
Explain:
Just ignore every first element in sub array in query.
So we will get a new query like this query = [[5], [1, 1], [5]]
Only record the result when meet the single number in new query array.
And the rule of record is find the sum of the single number.
The example above is 5 = 1 + 4
and 5 = 2 + 3
, there are two result.
So currently the output is [2]
When we meet the array length is larger than 1, such as [1, 1]
. That means we will replace the b[x] = y
, x is the first element, y is second element. So in this example, the b will be modify like this b = [1, 4]
And finally, we meet the [5] again. So we will find sum again. This time the result is 5 = 1 + 4
.
So currently the output is [2, 1]
note: Don’t have to modify the query array, just ignore the first element.
Time:
Function findSum is O(a * b)
Function modifyArrayb is O(1)
Function treverse is O(query)
So total maybe O(a * b * query)
I think this problem must has some better solution, but I am almost run out of time.
谢谢楼主!