Roblox OA records – hackrank – codesignal – 一亩三分地 – OA 代写 – OA 辅助 – OA help

限时50分钟,2道简单的算法题

Reminder: At Sentry, we find tremendous value in understanding the steps you take to get to a working solution. At any point during this test, you are not allowed to copy & paste any part of your solution into HackerRank (e.g., copying code from your IDE into HackerRank).

Given a string containing a sequence of words separated by whitespace-like characters, add underscores so that the words can be printed neatly given a character limit per line. Assume that there are no words that exceed the line’s width.

Your solution will take as input:

  1. A string of words separated by whitespace-like characters
  2. An integer representing the length which each line in the output must be

If there is any amount or type of whitespace between two words in the input string, they are considered separate words with the exception of hyphenated words (more information below about how to treat hyphenated words). For example, “hello world” and “hello world” lead to the same output.


Sample Input

"a cat is an animal"
6

The function should output the following:

['a_cat', 'is_an', 'animal']

Each element in the output is a line, each line has 6 characters (including underscores).


Even Underscore Distribution

There’s a catch: underscores should be distributed evenly between words in a line. When not possible, the extra underscores should be appended to the end of the line.

Therefore, given the following input:

"cat is an animal and so is a dog"
12

Your function should return:

["cat__is__an_", "animal__and", "so_is_a_dog"]

In this example, “cat__is__an_” has two underscores between each word because the words themselves have 7 characters, which leaves 5 underscores to be added. This allows us to add two underscores between each word, with one underscore left over to be added to the end because it couldn’t be evenly added between the words.

Line two, “animal__and”, can only contain two words, so we are allowed to add all the underscores between the two words.


Single Word Lines

If any of the lines end up having only 1 word on them, then instead of appending the extra underscores to the end of the line, we want to center the word. If the word can’t be exactly centered, as before, the extra underscore should be added to the end of the line.

For example, the input:

"human"
8

Will output:

["_human__"]

There are 3 underscores that need to be added so the 1 extra underscore goes to the end of the line.


Hyphenated Words

Hyphenated words (“self-inflicted”, “pre-approval”, “mother-in-law”) should be kept on one line, and the current line if possible. If the first part of the hyphenated word including the hyphen (“self-” from “self-inflicted”) fits while the whole word doesn’t, then the word should be split up across multiple lines.

Hyphenated words can have any amount of whitespace around the hyphens, but they should be treated as if there is no white space around the hyphens. For example, an input of “self-inflicted” and “self - inflicted” should lead to the same result.

For example, given the following input:

"auto-complete is my go  -  to"
8

Your function should return:

["_auto-__", "complete", "is__my", "-go-to__"]

In this example, “auto-complete” cannot fit on the line, so we split it up and have “auto-” on the first line. Even with the extra whitespace, we treat it as “go-to”, which fits on one line so there is no need to split it up.

我们长期稳定承接各大科技公司如Roblox、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 *