re: Daily Coding Challenge #79 VIEW POST


My solutions in Haskell. I have not run them against LeetCodes tests since they don't support Haskell, but I think they're correct. I did another more complex solution to the second one, but after testing some numbers I realized it was just the Fibonacci sequence.

findNextGreater nums n = 
    let x = dropWhile (< n) $ tail $ dropWhile (/= n) nums 
    in if null x then -1 else head x

nextGreaterElement nums1 nums2 =
    map (findNextGreater nums2) nums1
fib a _ 0 = a
fib a b n = fib b (a+b) (n-1)

climbStairs = fib 1 1
code of conduct - report abuse