Collections / Algorithm
Find four primes
Recently I was looking for a job. Most companies send a paper test before on-site interview.Last month, I received a test as below:I have four different prime number all under 1000. I have noticed that the product of these primes is a twelve-digit number whose digits are either sequential or the same as previous one.
It is a simple task of sorting on Codility online lesson.A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P < Q < R < N).I used Array.Sort to sort the array firstly. Then get the largest 3 elements or the largest 1 element and the smallest 2 elements.
It is an easy exercise. The key point is making clear what you want to know during the iterating of the Array. In this question, the keys are current lowest point and current max profitAn array A consisting of N integers is given. It contains daily prices of a stock share for a period of N consecutive days. If a single share was bought on day P and sold on day Q, where 0 ≤ P ≤ Q < N, then the profit of such transaction is equal to A[Q] − A[P], provided that A[Q] ≥ A[P]. Otherwise
You are given integers K, M and a non-empty array A consisting of N integers. Every element of the array is not greater than M.You should divide this array into K blocks of consecutive elements. The size of the block is any integer between 0 and N. Every element of the array should belong to some block.