Problem · String

Backtick Identifier Converter

Learn this problem
EasyHudson River TradingOA

Problem statement

You are given a string text. Some identifiers in the string are wrapped in backticks, such as `user_id`.

For every backtick-wrapped identifier:

  • If the identifier is an all-uppercase constant, leave it unchanged.
  • Otherwise, treat it as a snake_case function or variable name and convert it to camelCase.

Return the full string after converting only the text inside complete backtick pairs. Preserve the backticks and all text outside them.

An identifier is treated as an all-uppercase constant when it contains at least one letter and every letter in it is uppercase. Underscores and digits do not affect this check.

Function

convertIdentifiers(text: String) → String

Complete convertIdentifiers.

  • String text: the text to transform

Returns

String: the transformed text.

Examples

Example 1

text = "Call `get_user_name` before reading `MAX_RETRY_COUNT`."return = "Call `getUserName` before reading `MAX_RETRY_COUNT`."

get_user_name is converted to camelCase, while the uppercase constant is unchanged.

Example 2

text = "Use `parse_http_response` and `user_id` now."return = "Use `parseHttpResponse` and `userId` now."

Both snake_case identifiers inside backticks are converted and the rest of the text is preserved.

Constraints

  • 1 <= text.length <= 10^5
  • text contains printable ASCII characters.
  • Backtick-wrapped identifiers contain letters, digits, and underscores.

More Hudson River Trading problems

drafts saved locally
public String convertIdentifiers(String text) {
  // write your code here
}
text"Call `get_user_name` before reading `MAX_RETRY_COUNT`."
expected"Call `getUserName` before reading `MAX_RETRY_COUNT`."
checking account