ForHosting KIT · Text & AI

Check string rotation

A string rotation keeps every character in the same circular order while moving a prefix from the beginning to the end, or equivalently moving a suffix to the beginning.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

This checker compares two strings and reports whether the second can be obtained by rotating the first by any number of positions, including zero positions. Matching is exact, so capitalization, spaces, punctuation, and Unicode characters remain significant. Because a rotation cannot add or remove characters, inputs of different lengths produce a clear validation error instead of a false result.

What counts as a string rotation

A rotation changes the starting point of a string without changing the circular sequence of its characters. For example, rotating “waterbottle” so that the first three characters move to the end produces “erbottlewat”. The candidate uses exactly the same characters in exactly the same cyclic order; only the boundary between the end and beginning has moved. A rotation by zero positions is valid, so a string always counts as a rotation of itself. Repeated characters do not change the rule, although they can make several rotation positions produce the same visible result. This check is stricter than testing whether two strings are anagrams. Anagrams may rearrange characters freely, while rotations preserve their order around the cycle. Matching is also case-sensitive and literal. Uppercase and lowercase letters are different, and spaces, punctuation marks, combining characters, and line breaks participate in the comparison. Supply the original value in `first` and the candidate in `second`; the result contains a single `is_rotation` boolean.

How the check works

The checker first validates that both fields are strings and that their lengths are equal. Equal length is a necessary condition: rotating a string never inserts or deletes a character. If the lengths differ, the request is rejected as invalid input so that a malformed comparison is distinguishable from a legitimate equal-length candidate that simply is not a rotation. For valid inputs, the implementation searches for the candidate across two consecutive traversals of the original string. Any rotation must appear within that circular search space. The search uses a prefix table to avoid restarting from the next character after every partial mismatch, giving deterministic linear behavior with respect to the input length. It does not call a network service, use a language model, consult locale rules, or normalize the text. Consequently, the same code-unit sequence always returns the same answer. Two empty strings are rotations of one another, and identical nonempty strings pass through the valid zero-position rotation case.

Interpreting results and preparing input

A result of `true` means there is at least one circular shift of `first` whose complete value equals `second`. A result of `false` means the strings have equal lengths but no shift produces an exact match. Before comparing text from different sources, decide whether exact matching reflects the problem you are solving. This capability intentionally does not trim whitespace, fold letter case, remove punctuation, or apply Unicode normalization, because any of those transformations would silently change the supplied strings. If your application considers “A” and “a” equivalent, or treats composed and decomposed Unicode forms as the same, normalize both values consistently before sending them. Preserve meaningful leading or trailing spaces when they are part of identifiers or encoded sequences. The base API price is $0.002 per request, while the browser version can execute the same deterministic logic locally. For automated tests, include positive rotations, equal-length negative comparisons, repeated-character cases, identical strings, and the unequal-length validation error to make the intended text policy explicit.

Validate circular buffer output

Confirm that a captured buffer contains the expected sequence even when reading began at a different position in the cycle.

Test coding exercises

Check expected answers for rotation problems without confusing circular order with unrestricted anagram matching.

Compare cyclic identifiers

Determine whether two equal-length representations describe the same repeating cycle with different starting points.

Does an unchanged string count as a rotation?

Yes. Rotating by zero positions is allowed, so every string is a rotation of itself.

Are uppercase and lowercase letters treated as equal?

No. Comparison is exact and case-sensitive, so uppercase and lowercase code units are different.

What happens when the strings have different lengths?

The capability returns an invalid input error because rotation cannot change the number of characters.

Is a string rotation the same as an anagram?

No. A rotation preserves circular character order, while an anagram can rearrange characters in any order.

Do empty strings count as rotations?

Yes. Two empty strings have equal length and match under the zero-position rotation.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/text/string-rotation-check

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/text/string-rotation-check \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"first":"waterbottle","second":"erbottlewat"}'
{
  "first": "waterbottle",
  "second": "erbottlewat"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "text.string_rotation_check",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_tokens20000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →