Hi Vikram,
Thanks a lot for your answer, that explains what is wrong!
Indeed, the transform() cannot be that "greedy" as I thought.
On Wednesday, 22 April 2020 03:17:24 UTC+8, Aditya Vikram Jain wrote:
>
> Hi Alexander,
>
> I used similar approach and I think I found out why it is wrong,
Hi Alexander,
I used similar approach and I think I found out why it is wrong, basically
the solution just assumes that we need to convert the solution into two
numbers which on xored give 0 and and the or operation between the two
gives 2^(n-1), but this approach marks many possible answers
>
> Quickly refactored the code:
>
import java.io.{BufferedReader, BufferedWriter, InputStreamReader,
OutputStreamWriter}
import java.util.Scanner
object Solution {
private def isPowerOf2(x: Long) = (x & (x - 1L)) == 0L
/**
* returns next power of 2 greater then x.
* Example: