puupil's blog

By puupil, history, 3 months ago, In English

A — Alternating Sum of Numbers

Tutorial
Solution

B — Three Brothers

Tutorial
Solution

C1 and C2 — Message Transmission Error(Hard Version)

Hint
Tutorial
Solution

Also if someone has solved C1 and C2 with KMP, please explain your solution.

  • Vote: I like it
  • +13
  • Vote: I do not like it

»
3 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Awesome

»
3 months ago, # |
  Vote: I like it +16 Vote: I do not like it

I actually used Z-Algorithm for C1+C2. The core concept of Z made it pretty intuitive: "check if prefix of length $$$x$$$ is equal to suffix of length $$$x$$$" can be rewritten as "check if $$$z_{n-x} = x$$$" in Z.

»
3 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Also for B, I hope I was not the only one being absurdly lazy and typed $$$6 - a - b$$$ as answers.

  • »
    »
    3 months ago, # ^ |
    Rev. 2   Vote: I like it +14 Vote: I do not like it

    Actually in Unix you can control file access permissions with same idea:

    1 + 2 + 4 = 7

    So it's not lazy it is common practice.

»
2 months ago, # |
  Vote: I like it +3 Vote: I do not like it

For the kmp solution in C

the prefix function returns an array $$$pi$$$, where $$$pi_i$$$ is the maximum length of a prefix which equals the suffix of the same length in the prefix of size $$$i$$$.

so for a prefix of size $$$n$$$ (the entire string) if $$$pi_n$$$ is less than or equal $$$n / 2$$$ even if the part that will be merged is of minimal length, we still can't use this string to form the given string. However if it's greater than $$$n / 2$$$ then after merging we always get the given string.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    My Implementation of the same: 278562557

  • »
    »
    2 months ago, # ^ |
      Vote: I like it -7 Vote: I do not like it

    does prefix function considers overlaps?

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      yes, say our string is $$$aaaaa$$$ then $$$pi_n$$$ would be $$$4$$$ since the suffix of length $$$4$$$ equals the prefix of length $$$4$$$

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it -8 Vote: I do not like it

        OH! didn't know that. thanks!

»
2 months ago, # |
  Vote: I like it +8 Vote: I do not like it

We don't accept editorials from persistent cheaters. Go away and take your shenanigans to Leetcode please.