Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) E1. Trails (Easy)
1945. Sum of Digits of String After Convert
You are given a string
s
consisting of lowercase English letters, and an integerk
.First, convert
s
into an integer by replacing each letter with its position in the alphabet (i.e., replace'a'
with1
,'b'
with2
, …,'z'
with26
). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operationk
times in total.For example, if
s = "zbax"
andk = 2
, then the resulting integer would be8
by the following operations:
- Convert:
"zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
- Transform #1:
262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
- Transform #2:
17 ➝ 1 + 7 ➝ 8
Return the resulting integer after performing the operations described above.
3277. Maximum XOR Score Subarray Queries
You are given an array
nums
ofn
integers, and a 2D integer arrayqueries
of sizeq
, wherequeries[i] = [li, ri]
.For each query, you must find the maximum XOR score of any subarray of
nums[li..ri]
.The XOR score of an array
a
is found by repeatedly applying the following operations ona
so that only one element remains, that is the score:
- Simultaneously replace
a[i]
witha[i] XOR a[i + 1]
for all indicesi
except the last one.- Remove the last element of
a
.Return an array
answer
of sizeq
whereanswer[i]
is the answer to queryi
.
3276. Select Cells in Grid With Maximum Score
You are given a 2D matrix
grid
consisting of positive integers.You have to select one or more cells from the matrix such that the following conditions are satisfied:
- No two selected cells are in the same row of the matrix.
- The values in the set of selected cells are unique.
Your score will be the sum of the values of the selected cells.
Return the maximum score you can achieve.
3275. K-th Nearest Obstacle Queries
There is an infinite 2D plane.
You are given a positive integer
k
. You are also given a 2D arrayqueries
, which contains the following queries:
queries[i] = [x, y]
: Build an obstacle at coordinate(x, y)
in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made.After each query, you need to find the distance of the
kth
nearest obstacle from the origin.Return an integer array
results
whereresults[i]
denotes thekth
nearest obstacle after queryi
, orresults[i] == -1
if there are less thank
obstacles.Note that initially there are no obstacles anywhere.
The distance of an obstacle at coordinate
(x, y)
from the origin is given by|x| + |y|
.
3274. Check if Two Chessboard Squares Have the Same Color
You are given two strings,
coordinate1
andcoordinate2
, representing the coordinates of a square on an8 x 8
chessboard.Below is the chessboard for reference.
Return
true
if these two squares have the same color andfalse
otherwise.The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first (indicating its column), and the number second (indicating its row).