Can someone explain this test case?


  • 7
    E

    EDIT: Solved; I just didn't read the question correctly. See the comments below for the correct understanding.

    [6,5,8,9,7,1,10,2,3,4]
    2

    Expected output is 8, but why isn't it 7?

    On the 7th day the flowers that have bloomed would look like this:
    6, 5, 8, 9, 7, 1,10, 2, 3, 4
    Y, Y, N,N, Y, Y, N, Y, Y, Y

    There are 2 flowers between the 7th flower and the 5th flower and they both haven't bloomed. 5 and 7 have both bloomed. Doesn't this satisfy the condition? Why is the answer not 7?


  • 0
    D

    description in where i and x will be in the range from 1 to N is wrong, it should be
    i in range from 0 ~ N - 1, means day 1 to day N and x in range 1 to N


  • 4
    S

    Hope below below explanation helps you -

    pots which bloom on day i is flowers[i] -   [ 6, 5, 8, 9, 7, 1, 10, 2, 3, 4] 
    Initial configuration of pots   - [  F, F, F, F,  F, F,   F,  F,  F, F]  (F not blooming, T blooming)
    
    indexing starts from 1
    
    day 1 - [  F, F, F, F,  F, T,  F,  F, F, F]  - pot 6 bloomed
    day 2 - [  F, F, F, F,  T, T,  F,  F, F, F]  - pot 5 bloomed
    day 3 - [  F, F, F, F,  T, T,  F, T,  F, F]  - pot 8 bloomed
    day 4 - [  F, F, F, F,  T, T,  F, T,  T, F]  - pot 9 bloomed
    day 5 - [  F, F, F, F,  T, T,  T, T,  T, F]  - pot 7 bloomed
    day 6 - [  T, F, F, F,  T, T,  T, T,  T, F]  - pot 1 bloomed
    day 7 - [  T, F, F, F,  T, T,  T, T,  T, T]  - pot 10 bloomed
    day 8 - [  T, T, F, F,  T, T,  T, T,  T, T]  - pot 2 bloomed and   between 2nd and 5th pot  2 (k=2) pots are non blooming, so answer is 8

  • 1
    J

    I also made the same mistake, and just noticed that flowers[i] = x: i is day and x is the position.


  • 0
    E

    Thanks, I understand now.


  • 6
    L

    Please grammar check the questions prior to the contest. English is my second language so poor grammar makes it incredibly difficult, if not impossible, for me to understand the question. Thank you!


Log in to reply
 

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