randomrandom1810's blog

By randomrandom1810, history, 21 month(s) ago, In English

This post was asked in online coding round of a company.

There are n servers. Ith server has requests[i] requests to serve but can serve a maximum of max_req[i] requests.
In order to balance the load, a hackers reed to redirect some requests of Ith server to some other servers. The latency induced in redirecting the request on the Ith server to the Jth server is |i-j| where |x| represents the absolute value of x. The max_latency is defined as the maximum latency Induced amongst all the redirections.
Given the arrays requests and max_req find the minimum possible max latency if the requests are redirected optimally such that no server has to serve more than the maximum requests it can serve. If there is no way to serve all the requests, report -1 as the answer.

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By randomrandom1810, history, 22 months ago, In English

We are provided with 2 integers, F and K and we want to find an integer N such that

  • N is divisible by F
  • N is a number whose sum of digits is an integer K

return minimum N satisfying the 2 conditions.

constraints

1 <= F <= 495

1 <= K <= 5000

Please tell me how to approach this problem.

Full text and comments »

  • Vote: I like it
  • +28
  • Vote: I do not like it