Embercode
✕
Dynamic ProgrammingQuick quiz

Palindrome counts and cuts

8 questions. Covers Palindrome partitioning and minimum cuts.

Questions 1 to 5 of 8

  1. 1. A string has 5 characters. How many centres does expandCount use?
  2. 2. Predict the output of this program. The palindromes are printed in the order they are found. ``cpp #include <cstddef> #include <iostream> #include <string> #include <vector> long long expandCount(const std::string& s, std::vector<std::string>* out) { const int n = static_cast<int>(s.size()); long long count = 0; for (int c = 0; c < 2 * n - 1; ++c) { int l = c / 2; int r = l + (c % 2); while (l >= 0 && r < n && s[l] == s[r]) { ++count; if (out) out->push_back(s.substr(l, r - l + 1)); --l; ++r; } } return count; } int main() { std::vector<std::string> list; expandCount("bb", &list); for (std::size_t i = 0; i < list.size(); ++i) { std::cout << list[i] << (i + 1 < list.size() ? "," : "\n"); } } ``
  3. 3. Which statements about expandCount are true? Pick all that apply.

    Pick every answer that is true.

  4. 4. How many palindromic substrings does aaaa have, counted by position? Give a number.

    Type your answer.

  5. 5. Why does tableCount test len <= 2 before it reads isPal[i + 1][j - 1]?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.