Google 电面

您将获得两个字符串A和B(由小写英文字母组成)。 您的目标是通过连接字符串B的多个副本来形成字符串A.但是,在连接字符串B的副本之前,您可以从中删除任意数量的字符。

1 个赞

举个例子?

这道题我用的memo + dfs的解法,时间复杂度大概是o(m^2 + n^2);这哥们说还有更好的。。。。用双指针,hmm。。。。可能我比较菜

A = zaza

B = baz
##z + #az + #a#

##z + #a# + ##z + #a#
返回3

你做复杂了,我回头贴下代码
直接从左到右扫就行

可以

参考这个

啊。。。我误解错提议了。。。。

好像和利口药0五五差不多?

2 个赞

前两天的电⾯

  1. Sum of all perfect squares less than n. so if n=10, answer is 1 + 4 + 9 = 14

  2. You are given a sorted list of distinct integers from 0 to 99, for instance [0, 1, 2, 50, 52, 75]. Your task is to produce a string that describes numbers missing from the list; in this case “3-49,51,53-74,76-99”. The items should be sorted in ascending order and separated by commas. When a gap spans only one number, the item is the number itself; when a gap is longer, the item comprises the start and the end of the gap, joined with a minus sign.

第⼀题⼆分

第⼆题 模拟

也报一下

Given an array of integers ‘arr’ and a set of queries of the form [left, right, n], your task is to find the number of occurrences of the number n in the inclusive subarray arr[left…right] (0-based), for each query. Return the sum of the answers for all queries as the result.

Example
arr = [1, 2, 1, 3, 1, 2, 1]
queries = [[1, 3, 3], [0, 4, 1], [2, 5, 2], [5, 6, 1]]
The output should be 6.

新鲜出炉的面经,只有一道题,但是有fu

Given a binary tree, where an arbitary node has 2 parents i.e two nodes in the tree have the same child. Identify the defective node and remove an extra edge to fix the tree.

Follow-up 1:

What if the tree is a BST?

Follow-up 2:

What if the tree is an N-ary tree?

参考 Google onsite - 其中有难题 Remove Extra Edge - #6 by Xavier

/https://leetcode.com/problems/unique-paths-ii/

Follow up:

what if the robot has a skill to convert a 1 to 0, max path after using this skill

check if white is captured by black.
white move: 0
black move: 1
input: board, coordinates of white move
return: true if captured

Example:
input:
1 1 1 1 1
1 1 0 1 1
1 1 0 0 1
1 1 1 1 1
x: 1
y: 2

return true
the white moves are captured by black

input:
1 1 - - -
1 1 0 1 -
1 1 0 0 -
1 1 1 1 1
x: 1
y: 2

return false
not captured by black

Given a two 2D integer array, find the max score of a path from the upper left cell to bottom right cell that doesn’t visit any of the cells twice. The score of a path is the minimum value in that path.

For example:

Input:

[7,5,3]
[2,0,9]
[4,5,9]

Here are some paths from [0,0] to [2,2] and the minimum value on each path:

path: 7->2->4->5->9, minimum value on this path: 2

path: 7->2->0->9->9, minimum value on this path: 0

path: 7->2->0->5->9, minimum value on this path: 0

Notice: the path can move all four directions. (not only right and down. ALL FOUR DIRECTIONS)

Here 7->2->0->5->3->9->9 is also a path, and the minimum value on this path is 0.

The path doesn’t visit the same cell twice. So 7->2->0->5->3->9->0->5->9 is not a path.

In the end the max score(the min value) of all the paths is 3.

Output: 3