Monthly Archives: November 2020

Dockerfile CMD requires foreground command

Start a docker container with below Dockerfile. Since it has CMD [“nginx”]. The docker container exists after nginx command is finished. It couldn’t be connected even with –detach mode.

In order to keep the docker container running, needs the CMD run in foreground. Let it keep running. So it needs a “daemon off” in nginx.conf file.

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y nginx


#RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf

CMD ["nginx"]

EXPOSE 80
EXPOSE 443

 

 

lc1639

Considering words = [“acca”,”bbbb”,”caca”], target = “aba”

dp[1][2] means the result for target “ab” and words=[“acc”, “bbb”, “cac”]

To calculate dp[i][j]:

1. dp[i][j] = dp[i][j – 1]. This means when words has is 1 letter small, the result to cover target[0,…,i]. In this case, dp[2][3] = dp[2][2]

1639_3

2. In words array, for j column, when there is x number of letters which equals to target[i]. It is ‘a’ for this case. Then needs to add dp[i-1][j-1] * x. For dp[2][3], this part is result of [“acc”, “bbb”, “cac”], “ab”, multiplying number of ‘a’ in column 3, which is 2.

1639_2

For each column of the words, create a count[column][26] to mark the number of letters in that column.

lc1648

This problem needs to aggregate to (num, count) tree map. Always stick to top 2 elements. After processed first element, aggregate the count of first element to second element.

For example, 77744444, orders = 10.

For TreeMap, it has (7, 3), (4, 5)

It can be added to answer by below numbers:

7 7 7  <– e1
6 6 6
5 5 5  <– e2

Orders is 8. All the numbers can be used to add into answer.

For one column, it is  5+6+7. The formula is (e2 – e1 + 1) * (e1 + e2) / 2 = 18

So answer = answer + 18 * 3

After that, tree map becomes to (4, 3), (4, 5). Merging them, it becomes (4, 8). Orders -= 9

 

Consider case 7774, orders = 8. (7, 3), (4, 1)

1648

Only numbers in red will be added to answer.

In this case, availRow = 8 % 3 = 2. mod = 8 / 3 = 2

One part, (e1 – e2 + 1) * (e1 + e2) / 2 * 3. 3 is the number of column.

Another part, (secondElement.key + 1)*mod = (4 + 1) * mod = 5 * 2 = 10

lc1641

Assume a, e, i, o, u variables mean the number of elements which starts with a, e, i, o, u. Take below as example, length is 5 now. There are a number of elements which starts with a, e number of elements which starts with e, etc.

When extend the length to 6.

When adding a, a can be added in any elements.

When adding ee can be added in front of elements starting with e, i, o, u.

When adding ii can be added in front of elements starting with iou.

When adding oo can be added in front of elements starting with ou.

When adding uu can be added in front of elements starting with u.

lc1641

The elements are lexical order. This is an important criteria.

link