• + 1 comment

    I am just a fresh man in Haskell, and I have already know the lazy evaluation, so I can't understand why my following answer can't get result for the input of 100. Any advice will be appreciated! Thx a lot!

    nLevelBST n = rem (sum([nthLevelBST 1 t n | t <- [1..n]])) (10^8 + 7)
    
    nthLevelBST l m r
        | l == m && m == r = 1
        | l == m && m /= r = sum([nthLevelBST (m+1) mr r | mr <- [(m+1)..r]])
        | l /= m && m == r = sum([nthLevelBST l ml (m-1) | ml <- [l..(m-1)]])
        | otherwise = (sum([nthLevelBST l ml (m-1) | ml <- [l..(m-1)]])) * (sum([nthLevelBST (m+1) mr r | mr <- [(m+1)..r]]))