You've built your first microservice. Service A needs to call Service B. How does it know where Service B is?
Simple. "Just put Service B's IP address in Service A's configuration file."
but this is one of the most common and brittle design choice...π§΅
D. If n==1 or n==2, not possible, it is possible for n=3, so it can be made possible for n>=3. For n=3, map (1,3),(2,2),(3,1) (sum = 4 not prime). For other entries, map (p[i], a[i]=p[i]), so that remaining elements add up to 2*p[i] which is not prime.
C. gunHits = ceil(h/x), and cases for laser, if only y1 damage suffices then min(gunHits, ceil(h/y1)), otherwise if used k y1 damage hits, update health as (h-k*y1) and count additional no. of hits of y2 damage required which amounts to ceil(h/y2), print min(gunHits, laserHits).
A. Print 'K' followed by x%100 for x<=1999 or x>=2010, and print 'K0' followed by x%10 otherwise.
B. Traversing from the left, if there is a character such that s[i] > s[i+1] remove s[i], otherwise remove last character.
D. () Sort a,b. Maintain two pointers l1,r1 for a and l2,r2 for b. d += max(|a[l1]-b[r2]|, |a[r1]-b[l2]|), and move the pointer suitably. At each step, we are making a greedy choice, so recursion can also be used, but that gives TLE. Simple iteration yields max. d. O(nlogn+n)
C. Have to be greedy about phone's battery. If at some moment m[i] switching off and turning on loses less energy, pursue this, otherwise let battery drain at normal rate. If at the end of this practice, count of messages equals n, then all messages were sent, otherwise not.
B.(contd) If cntF >= cntS, either we already have as many 1s as we require or we can introduce them directly in the correct places, in either case, the number of operations is equal to the number of indices i where f[i]='1' and s[i]='0'.
A. Area = s*s where s = max({x})-min({x})
B. Let cntX denote 1s in X. If cntF < cntS, then we have to introduce additional 1s that takes (cntS-cntF) operations and we can insert them in the correct places, for the remaining 1s out of place we can put each in place in 1 operation
B. (Optimal) Create sliding window of capacity k. Reverse sort array. Move window upto k, every element removed is denied possible negation, so add it to sum., add removed element, subtract new included element twice. Choose max. sum. O(t(nlog(n)))
A. Find |k| within an interval, where max({a})<=k<=min({b}) and k!={c}. cnt = (min({b})-max({a})+1)-|{c}|. If min({b})<max({a}), print 0.
B. Sort array. Iterate over no. of removals, multiply x largest by -1. Evaluate maximum sum. O(t(nlog(n)+kx))