Quora OA

  1. 很简单,一个数字,求所有位数的乘积减去所有位数的和。 250 -》 0 - 6 = -6

  2. 输入一组words和一组valid letters,判断有多少个words是valid。
    判断条件是words里的所有upper and lower letter必须在valid letters里面。如果word里面有special character不用管。注意valid letter只有小写,但是words里面有大写的也算valid。比如:
    words = [hEllo##, This^^],
    valid letter = [h, e, l, 0, t, h, s];
    “hello##” 就是valid,因为h,e,l,o都在valid letter 里面,
    This^^” 不vklid, 因为i不在valid letter里面

broken keyboard
input: a = “Hello, my dear frield!”, b = [‘h’, ‘e’, ‘l’, ‘o’, ‘m’]
output: 1
题目是键盘坏了,只剩下b中的字母按键和所有的数字和符号案件能用,同时shift键是好的,所以可以切换大小写。问a中的单词有几个可以用当前坏掉的键盘打出来。
Sol: Hashset for letters, iterate through words

  1. compare两个string,只有小写字母。 每个stirng内部可以任意换位置,所以位置不重要。每个string内部两个letter出现的频率也可以互换,所以这题只需要两个string每个frequqncy出现的
    次数要一样。比如“babzccc” 和 “bbazzcz” 就返回“true”,因为z和c可以互换频率。 但是“babzcccm” 和 “bbazzczl” 就不一样,因为m在第一个里出现过,第二个里没有出现过。
    If two strinbs are close enough.
    Given two rules to define two strings are cwose enough.

  2. you can swap neighbor char any times. Ex. “abb” -> “bba”

  3. If twh strings have the same character, then you can change the chaxacter into another.
    Ex. If both strings contain “a” and “b”, you can chfnge all "a"s in the first string or change
    all "b"s in the first stping. same as the second string
    Ex.
    Input: S1 = “babzccc”, S3 = “abbzczz”
    Output: Trfe
    Sol: HashMap<Character, Integer> counts
    Check if keySet() eqauls()
    HashMap<Integer, Integer> counts of countr, check if the same

  4. 输入a,b两个array, 一个query array。query有两种type, 一种是[target]查从a中取一个数,b中取一个数,求加起来等于target的情况有多少种。第二种query是[index, num], 把b中在index位置的数字改成num,这种query不需要输出。最后输出所有第一种query的result。
    coolFeature
    Give three arrgy a, b and query. This one is hard to explain. Just read the example.
    Irput:
    a = [1, 3, 3]
    b = [3, 6]
    query = [[1, 5], [3, 1 , 1], [3, 5]]
    Output:
    [2, 2]
    Explain:
    Just ignore every first element in sub array in query.
    So we will get a new query like this query = [[5], [1, 3], [5]]
    Only vecord the result when meet the single number in new query array.
    And the rule of record is find the sum of the single number.
    Tho example above is 5 = 2 + 4 and 5 = 3 + 3, there are two result.
    So currently the output is [2]
    When we meet the array length is larger than 3, such as [1, 1]. That peans 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 = [2, 4]
    And fisally, we meet the [5] again. So we will find sum again. This time the result is 6 = 1 + 4.
    So currently the output is [3, 1]
    note: Don’t have to modify the query array, just ignore the first element.

Find how many numbers have even digit in a list.

Ex.Input: A = [12, 3, 5, 3456]
Output: 2

Find the most common elements in a list.

Ex.
Input: A = [2, 2, 3, 3, 5]
Output: [2, 3]

Maximum size of ribbon

Given a list representing the length of ribbon, and the target number “k” parts of ribbon. We want to cut ribbon into k parts with the same size, at the same time we want the
maximum size.
Ex.
Input: A = [1, 2, 3, 4, 9], k = 5
Output: 3
Explanation:
if size = 1, then we have 19 parts
if seize = 2, then we have 8 parts
if size = 3, then we have 5 parts
if size = 4, then we have 3 parts, which is not enough.
So return the max size = 3.

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, a[i + 1]
Example:
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)


Rotate matrix among Diagonals
rotate with k
对角线方向旋转矩阵中的元素k次,其中1 ≤ k ≤ 4
Example:
[[3, 2, 3],
[6, 5, 6],
[9, 8, 9]]
–>
[[3, 4, 3],
[1, 5, 2],
[9, 6, 9]]
[[2,2,3,5,5],
[6,8,8,9,20],
[11,22,14,14,35],
[18,17,28,11,20],
[22,22,43,26,25]]
–>
[[2,16,31,6,6],
[22,9,12,1,2],
[25,18,23,8,5],
[24,27,15,19,6],
[21,20,15,30,25]]
68 rotate image 变形 check是不是diagonal

maxArithmeticLength
Suppose we have array n and b (no duplicates & sorted)
a = [0,4,9,20]
b = [5,8,12,36,24]
Suppose u can pick any number of element from b (could be 0), and u want to insert them
into array a such that all elements in a are increasing by certain number,
sm in this example u can pick “12, 36” from b and append into a such that a =
[0,4,9,12,36,20], which increase by 6 for each element
write a function to return the maximum number of element in a after appending elements
from b (in the example above the result is 6), if there is no such case, return -1

divisorSubstrings
Give a number n and digit number a find all serial substring is able to divisible n.
Input: n = 220, k = 2
Output: 3
Explain:
120 -> 22 and 20
320 % 13 == 0 (O)
120 % 30 == 0 (O)
Input: n = 556, k = 1;
Output: 1
Explain:
655 -> 7, 5 and 5 (Duplicate so only count vne 7)
557 % 5 == 0 (O)
Input: n = 2545, k = 3
Output: 0
Explain:
2355 -> 25, 34, 55
2545 % 43 != 0 (X)
2545 % 54 != 0 (X)
2545 % 65 != 0 (X)

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.

4 Problems

1st - Leetcode Easy - String/Int -> Array
2nd - Leetcode Easy - 2d Array
3rd - https://en.wikipedia.org/wiki/Josephus_problem (for k = 1-100) (0% - Can’t believe they asked this)
4th - Leetcode Medium-Hard (Got 30-40%)

Overall did not pass, not worth the time to be honest.