Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 782 |

@arpitsatnalika | 773 |

@tujhekya | 602 |

@code_it_ | 591 |

@prakharxyz | 589 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@Rahul Jadhav 1 | 466 |

@sivanandh03 | 464 |

Complete Leaderboard |

Given a positive integer **N**. The task is to check if N is a power of **2**. More formally, check if** N **can be expressed as **2 ^{x} **for some

**Example 1:**

Input:N = 1Output:trueExplanation:1 is equal to 2 raised to 0 (2^{0}== 1).

**Example 2:**

Input:N = 98Output:falseExplanation:98 cannot be obtained by any power of 2.

**Your Task: **Your task is to complete the function **isPowerofTwo**() which takes **n **as a parameter and returns **true or false** by **checking** is given number can be represented as a power of two or not.

**Expected Time Complexity:** O(log N).

**Expected Auxiliary Space:** O(1).

**Constraints:**

0 <= N <= 10^{18}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Power of 2

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.