Maximizing XOR Discussions | Algorithms | HackerRank

Sort by

recency

|

492 Discussions

|

  • + 0 comments

    Java solution using sort:

    public static int maximizingXor(int l, int r) {
            List<Integer> xors = new ArrayList<>();
            
            for (int i = l; i <= r; i++) {
                for (int j = l; j <= r; j++) {
                    xors.add(i ^ j);
                }
            }
            
            Collections.sort(xors);
            
            return xors.get(xors.size()-1);
        }
    
  • + 0 comments

    Here is my easy and straitghforward solution, you can watch video here : https://youtu.be/pCU8W_ofvDg

    int maximizingXor(int l, int r) {
        int result = 0;
        for(int a = l; a <= r; a++){
            for(int b = a; b<= r; b++){
                result = max(result, a ^ b);
            }
        }
        return result;
    }
    
  • + 0 comments

    Vedu Movie App is a streaming app that offers a wide range of movies, TV shows, and exclusive content with personalized recommendations. It features offline viewing, flexible subscription options, and social sharing for users to discuss and enjoy content together.

  • + 0 comments

    Simple and Easy Solution in Python If helps you please upvote to help others

    maximum=0
        for i in range(l,r+1):
            for j in range(i,r+1):
                print(i,j)
                val=i^j
                maximum= max(maximum,val)
        return maximum
    
  • + 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