harshsingh-io / Java.DSA

Unlock the power of Data Structures and Algorithms in Java! Dive into a world of efficient coding with our collection of Java DSA implementations and tutorials. Join us on the journey to mastering problem-solving and algorithmic thinking.
https://harshsingh-io.github.io/portfolio/
9 stars 23 forks source link

Create MaximunAndValue.java #11

Closed Sarthak9504 closed 8 months ago

Sarthak9504 commented 9 months ago

This algorithm is to find the maximum AND value of any two elements in an integer array. It makes use of bit manipulation techniques. The algorithm is as follows:

  1. First take the input of all the test cases to performed on this algorithm
  2. Then iterate through each test case and write the elements of the test case into the array
  3. Write a function that finds the maximum AND value between two elements from the array and initialize an integer variable called answer to 0
  4. In the function iterate through each bit from left (MSB to LSB) then set i-th bit of the variable.
  5. Now count the number of elements in the array that have the same i-th bit same.
  6. Now if the the number is greater than or equal to 2 update answer.
Sarthak9504 commented 9 months ago

Please Review my PR @harshsingh-io

Sarthak9504 commented 8 months ago

Hey @harshsingh-io please review my PR