Indeed计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(15)
OOD(0)
Algorithm(15)
System Design(0)
高频题(2)
Math(0)
全部(15)
OOD(0)
Algorithm(15)
System Design(0)
高频题(2)
Math(0)
1.Word Search in Grid
2.Counting Good Strings from Character Array
3.Counting Number of Islands in a 2D Grid
4.Word Processor
5.generate matrix
6.纸牌游戏
7.Counting Good Strings Formed by Characters
8.Sliding Window Moving Average Calculation
9.Compress Binary Tree
10.日志查询
11.Find unique word path
12.跳格子
13."Alert System for Frequent Keycard Use"
14.Counting Good Strings Formed by Characters
15.Word Search in Grid
1. Word Search in Grid
Given an m x n grid of characters board and a string word, return true if word exists in the grid.

The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

 

Example 1:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
Output: true

Example 2:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
Output: true

Example 3:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
Output: false

 

Constraints:

  • m == board.length
  • n = board[i].length
  • 1 <= m, n <= 6
  • 1 <= word.length <= 15
  • board and word consists of only lowercase and uppercase English letters.
 

Follow up: Could you use search pruning to make your solution faster with a larger board?

2. Counting Good Strings from Character Array
You are given an array of strings words and a string chars.

A string is good if it can be formed by characters from chars (each character can only be used once).

Return the sum of lengths of all good strings in words.

 

Example 1:

Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output: 6
Explanation: The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.

Example 2:

Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
Output: 10
Explanation: The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.

 

Constraints:

  • 1 <= words.length <= 1000
  • 1 <= words[i].length, chars.length <= 100
  • words[i] and chars consist of lowercase English letters.
3. Counting Number of Islands in a 2D Grid
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

 

Example 1:

Input: grid = [
  ["1","1","1","1","0"],
  ["1","1","0","1","0"],
  ["1","1","0","0","0"],
  ["0","0","0","0","0"]
]
Output: 1

Example 2:

Input: grid = [
  ["1","1","0","0","0"],
  ["1","1","0","0","0"],
  ["0","0","1","0","0"],
  ["0","0","0","1","1"]
]
Output: 3

 

Constraints:

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 300
  • grid[i][j] is '0' or '1'.
4. Word Processor
/*
We are building a word preocessor and we would like to implement word wrapping functionalitu that is a bit smarter.

Some users want to have the resulting lines to be as balanced as possible for higher redability. Therefore, Our application should divide a given text into a sequence of lines so that every line spans at most some fixed width and the difference between different lines are as little as possible.

We define the balance score of a collection of string as follows: find the longest line. For each line, sum the square of the length difference between this line and the longest line.

Given a string of the text and a maximum number of characters in a line, return a list of strings which result in the lowest balance score(on a tie, return any of the valid solutions).


Note: we are using '-' instead od space between words to make testing and visual verification of the result easier.

Examples:

text1='Seven six eight thirteen four five sixteen'

balance Wraplines(text1, 15)"balance the lines of text 1 wrapping to a max 15 length"=>

["Seven-six-eight"// 0
"thirteen-four",// 2*2
"five-sixteen" ]//3*4=score of 13

text 2 =XXXXXX X XXXX X X XXXX";

balanceWrap lines(text2, 9) "balance the lines of text2 wrapping to a max 9 length"=>

Correct answer(each line wrapped to a different length <=9)

["XXXXXX-X", //0*0
"XXXX-X", //2*2
"X-XXXXX"] //1*1 = score of 5

Or

["XXXXXX", //0
"X-XXXX-X", //0
"X-XXXXX"] //3*3 = score of 9

All Test Cases:
 test, max line length
balanceWrapLines(text1, 15)
balanceWrapLines(test2, 9)

n=number of words OR total characters
m=length of longest line
*/
5. generate matrix
给你一个string和两个数字col row,这个string可以根据row col来拆成matrix,然后你需要transpose这个matrix再输出
比如 [[a b c][d e f] [g h i]transpose成[a d g] [b e h] [c f i]初然后按顺序拼成一个string输出