TopcoderArchive
TCO9 Jan 2019
TCO19 SRM 746

FindStringHard

Problem statement, definition, constraints, and public examples.

Problem Statement

An antipalindrome is a string which differs from its own reverse at all positions. For instance, "ab", "aabb", "abab", and "abbaab" are antipalindromes, whereas "aaab", "abba", "aababa", "baa", and "a" are not.

A substring is a nonempty contiguous part of a given string. For instance, "aba" is a substring of "aaba" but "aaa" isn't.

Two substrings are considered different if they are located at different positions in the string. For instance, there are two distinct substrings "aba" in the string "ababa".

You are given an int n. Find and return any string with the following properties:

  • Its length is at most 100.
  • Each character is either 'a' or 'b'.
  • The string has exactly n antipalindromic substrings.

Definition

Class:
FindStringHard
Method:
withAntipalindromicSubstrings
Parameters:
int
Returns:
String
Method signature:
String withAntipalindromicSubstrings(int n)
(be sure your method is public)

Notes

  • It can be shown that the answer always exists. If there are multiple solutions, you may print any of them.
  • It is not necessary to minimize the length of the returned string.

Constraints

  • The integer n will be between 0 and 1000, inclusive.

Examples

  1. 3
    Returns: "bbaab"
    The three antipalindromic substrings of "bbaab" are "bbaa", "ba", and "ab".
  2. 8
    Returns: "ababbaab"
    The eight antipalindromic substrings of "ababbaab" are three copies of "ab", two copies of "ba", and one copy each of "abab", "bbaa", and "abbaab".
  3. 139
    Returns: "ababaabbaabbaaabbbaaabbbaaaabbbbaaaabbbbaaaaabbbbbaaaaabbbbbaaaaaabbbbbbaaaaaabbbbbb"
Back to all problems