Maximizing XOR Discussions | Algorithms | HackerRank
  • + 0 comments

    Haskell

    module Main where
    
    import Data.Bits (xor)
    
    solve :: Int -> Int -> Int
    solve l r = maximum [a `xor` b | a <- [l .. r - 1], b <- [a .. r]]
    
    main :: IO ()
    main = do
        l <- readLn :: IO Int
        r <- readLn :: IO Int
        print $ solve l r