[HRT] OA 2025 start – 25 Apr (generic)

Question 1

Description

In the "Challenges" section on CodeSignal a user can solve one of the existing challenges or submit their own. Each challenge has its own scoreboard organized by programming language. Solutions in these scoreboards are sorted according to their length. When the length of a solution is calculated, all comments and spaces are ignored. Your task is to implement a simplified version of this length calculator.

Assume that there are only two types of comments:

  • line-comment: starting with // and ending at the end of the line.
  • block-comment: starting with /* and ending with the first occurrence of */. It may span several lines.

Each non-space character outside comments adds 1 to the total length.

Note that all characters inside each comment are ignored, so they don’t introduce nested comments. See the examples for more details.

Also note that outside any other comment both // and /* start a new comment (i.e. in this task you don’t have to consider the cases where //, /*, or */ appear inside a string literal).


Question 2

Description

A circle circle(x, y, r) is defined by a center (x, y) and a radius r. It consists of all points (a, b) such that:

(a - x)^2 + (b - y)^2 <= r^2

Given integers (x, y, r), find the number of points (a, b) with non-negative integer coordinates in circle(x, y, r).

Example

  • For the input (2, 3, 1), the answer should be 5.
The 5 points are shown in blue here:
(2,3), (2,2), (2,4), (1,3), (3,3)

Question 3

Description

You have a string s that represents a chemical reaction.

The chemical reaction is a string in the following format:
molecule (+ molecule)* = molecule (+ molecule)*, where * means any non-negative number of repeats.

For example:

"A = B",  
"A = B + C",  
"A + B + C = D + E + F"

are chemical reactions, but:

"X + Y =",  
"X = X + Z"

are not.

A molecule is a concatenation of a coefficient (optional) and a string that represents the concatenation of elements and their coefficients (optional). A coefficient is a positive integer that doesn't exceed 1000, and it represents the number of repeats.

For example:

  • "Cu12" means 12 repeats of "Cu" element.
  • "H3O2" means 3 repeats of "H" element and 2 repeats of "O" element.
  • "O" means 1 repeat of "O" element.
  • If a coefficient is absent, the element repeats once.

An element is a string that starts with an uppercase English letter, while every other symbol is a lowercase English letter.

For example:

  • "A" and "Abc" are elements.
  • "FF" and "hello" are not.
  • "FF" actually indicates that there are 2 repeats of the "F" element.

A chemical reaction is considered to be balanced if every element has the same number of repeats on both sides of the chemical reaction.

Check whether the given chemical reaction is balanced.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *