谷歌店面

Print all the fractions from 0 to 1 with N being the highest denominator. The fractions must be printed in order. If duplicate fraction values are found, then print the fraction in the lowest form. For example, If you have 1/2 and 5/10, then only 1/2 would printed.

Example

Input: n = 4
Output: [“0/1”, “1/4”, “1/3”, “1/2”, “2/3”, “3/4”, “1/1”]

Given two input list:
A = [0,4,8,16]
B = [0,2,6,12,14,20]
( you can assume A and B are originlly sorted )
What is the max number to choose from B to be merge into A so that A can be a valid arithmetic sequence? ( you can insert elements of B into any place in A )

1 Like

考了 remove at most K element to make array increasing

given an array, please check if we can remove at most one element to make it strictly increasing.

ie1. [1,2,3,7,5,6], TRUE
ie2. [1,2,3,7,8,4,5] FALSE
follow up, what if at most 2?
follow up, what if K?

firstly see K = 1, I focus too much on remove element, but it’s just a longest increasing sequence problem.

其实就是 https://www.geeksforgeeks.org/convert-to-strictly-increasing-integer-array-with-minimum-changes/

return (arr.size() - longest_increasing_element_cnt) >= K;

我考了两道

Given m*n matrix, only have value 0 and 1. Write a function to count how many squares make by value 0 can be found in the given matrix.

Example:
[[0,0,0]
[0,0,0]
[0,0,1]]
return 11.

In len 1, there are 8 squares there.
In len 2, there are 3 squares there.
In len 3, there are 0 square there.
So total is 11.

There are m zombies and n humans at war with each other. Each army has a kill ratio which determines how many of each army will die in each round. After each human dies, it becomes a zombie and after each zombie dies - it just dies. Find the number of rounds it would take for an army to win and also return which army won.

Eg:
m = 10
n = 10
killRatioZ = 0.2 (i.e., zombies can kill 2 humans in each round)
killRatioH = 0.3 (i.e., humans can kill 3 zombies in each round)

return the number of rounds. Obviously the zombies will win here.
The value for kill ratios will be always 0.0 < ratio < 1.0

You start at index 0 in an array with length ‘h’. At each step, you can move to the left, move to the right, or stay in the same place(Note! Stay in the same place also takes one step). How many possible ways are you still at index 0 after you have walked ‘n’ step?

Example: n = 3

  1. right->left->stay
  2. right->stay->left
  3. stay->right->left
  4. stay->stay->stay

You are working at a factory and are in charge of the software of a machine that cuts sheets of glass. A sheet of glass is divided into little areas each one with an imperfection score, where 0 means perfect and larger means more imperfections. For example:

A larger glass sheet:
0.0, 0.1, 0.0, 0.4, 0.8, 0.2, 0.3, 0.1

Your task is to cut the larger glass sheet into smaller pieces of length L, such that the total sum of imperfections is less than or equal to I. The level of imperfection of a smaller piece of glass is the sum of the imperfections of the areas inside it. We want the number of smaller glasses to be maximal.

Continuing with the example:
For L = 2, I = 0.4, you can cut the larger piece into 3 pieces that match the quality constraint.
(0.0, 0.1), (0.0, 0.4), 0.8, 0.2, (0.3, 0.1)

Your program should output the largest number of glass sheets that can be produced, in this case is 3

Your input is:

  • Array with the quality levels of each area of the large glass sheet.
  • How long the small pieces should be.
  • Maximum imperfection level of the smaller pieces (sum of the areas that are part of it).

Output:
Integer telling me how many compliant smaller pieces can be cut.

Given a digital input stream,
The average value of the last last k value is required, and in the calculation,
it is required to remove top5% and bottom5% of the k numbers.

Follow up- Can you do in linear time?

Given a list of Coordinates (x, y) in a 2D Matrix, get two points that have the closest Manhattan Distance.

You start at index 0 in an array with length ‘h’. At each step, you can move to the left, move to the right, or stay in the same place(Note! Stay in the same place also takes one step). How many possible ways are you still at index 0 after you have walked ‘n’ step?

Example: n = 3

  1. right->left->stay
  2. right->stay->left
  3. stay->right->left
  4. stay->stay->stay

Can anyone solve it in n^2