Not understanding a test case. Can someone help please?


  • 3
    C

    Hi all:

    Perhaps I am just misunderstanding the problem, but for the example of n=4 fence posts and k=2 colors, the OJ indicates that the output should be 10.

    Can someone help me understand why this is the case?

    Lets say the colors are red (R) and blue (B). The possible colorings are:

    RBRB BRBR

    RRBR RBBR RBRR

    BBRB BRRB BRBB

    Where am I undercounting?


  • 0
    J

    You are missing BBRR and RRBB.


  • 0
    C

    Thanks. I've misunderstood the problem then.

    "You have to paint all the posts such that no more than two adjacent fence posts have the same color."

    I think the problem should be reworded. The above seems to be imply that two adjacent fence posts to me means one pair of adjacent posts so BBRR and RRBB have two pairs of adjacent posts and thus should not be counted.


  • 0
    C

    @jim11 Thanks! I made the same mistakes


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.