I googled some but did not find a direct guide on the topic, so I considered it for some time and wrote this note for reference.
I was motivated to consider this because I was desining a microservice with a dedicated cache and message queue, but my colleague asked me not to do that. Unfortunately, neither of us had much knowledge to explain the approahces to others.
My initial thought was that a dedicated cache could make the microservice truly independent, and this fit our use case. My mind did not change after checking web pages and some consideration.
For simplicity, I will assume we're talking about Redis (I hear that Redis stopped being OSS, and we might want to migrate to other projects such as dragonfly tho).
The microservice is used by multiple services, and its workload is expected to increase hugely. Therefore, I believe having a dedicated Redis instance is better in our case, from the technical standpoint.
However, DevOps engineers and I have been busy and occupied with other tasks. It also makes sense not to add another overhead, considering our current team structure.
I'll use the shared infastructure for now.
Alice's winning strategy is to pick the most significant number with odd counts first. This move makes the count of remaining numbers no more than the first picked number even. After making the situation, any picks Bob makes are followed by Alice's pick of the same number, leading to Bob's defeat.
Simply put, Alice wins if there is a number with odd counts.
Examples
[2, 2, 3, 3] -> (alice, bob) => [(2, 2), (3, 3)] or [(3, 3)] => Alice loses
[1, 2, 2, 3, 3] -> (alice, bob) => [(1, 2), (2, 3), (3, _)] or [(1, 3), (3, _)] => Alice wins
from collections import defaultdict
for _ in range(int(input())):
int = int(input())
n: list[int] = list(map(int, input().split()))
a:
= defaultdict(int)
d for x in a:
+= 1
d[x]
for cnt in d.values():
if cnt % 2 == 1:
print("YES")
break
else:
print("NO")
from collections import defaultdict
for _ in range(int(input())):
n, m = map(int, input().split())
a: list[int] = list(map(int, input().split()))
counter = defaultdict(int)
for x in a:
counter[x] += 1
ans: int = 0
for sml, cnt in counter.items():
if sml + 1 not in counter:
cntmax: int = m // sml
ans = max(ans, sml * min(cnt, cntmax)) # I overlooked min() here
continue
# O(n) in total including the outer for-loop
# for each size of petals
# for i in range(occurrence of the size of petals)
for _cnt in range(1, cnt + 1):
if sml * _cnt > m:
break
remcoins: int = m - sml * _cnt
lrgcntmax = min(counter[sml + 1], remcoins // (sml + 1))
ans = max(ans, sml * _cnt + (sml + 1) * lrgcntmax)
print(ans)
second|
from collections import defaultdict
for _ in range(int(input())):
n: int = int(input())
a: list[int] = list(map(int, input().split()))
d: defaultdict = defaultdict(int)
for x in a:
d[x] += 1
ans: int = sum([1 if v == 2 else 0 for v in d.values()])
print(ans)
Ketone 10 mg/dl
Salad 30g Macadamia nuts 30g Protein shake 10g
Total carbohydrate 70 g
MUST:
TODO: