PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Snapchat

Check whether an integer is a power of two

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in bit-level reasoning and integer arithmetic, specifically understanding binary representations and the properties that define powers of two.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Check whether an integer is a power of two

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Given a signed 32-bit integer `n`, return `true` if `n` is an exact power of 2, otherwise return `false`. A power of 2 is a number of the form `2^k` where `k >= 0` (e.g., 1, 2, 4, 8, 16, ...). ## Input - `n`: an integer in the range `[-2^31, 2^31 - 1]` ## Output - Boolean indicating whether `n` is a power of 2. ## Examples - `n = 1` → `true` (2^0) - `n = 16` → `true` (2^4) - `n = 3` → `false` - `n = 0` → `false` - `n = -8` → `false` ## Follow-up - Aim for an `O(1)` / bit-manipulation solution (no loops over bits, and no precomputed set/table of powers).

Quick Answer: This question evaluates proficiency in bit-level reasoning and integer arithmetic, specifically understanding binary representations and the properties that define powers of two.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Jan 2, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
5
0
Loading...

Given a signed 32-bit integer n, return true if n is an exact power of 2, otherwise return false.

A power of 2 is a number of the form 2^k where k >= 0 (e.g., 1, 2, 4, 8, 16, ...).

Input

  • n : an integer in the range [-2^31, 2^31 - 1]

Output

  • Boolean indicating whether n is a power of 2.

Examples

  • n = 1 → true (2^0)
  • n = 16 → true (2^4)
  • n = 3 → false
  • n = 0 → false
  • n = -8 → false

Follow-up

  • Aim for an O(1) / bit-manipulation solution (no loops over bits, and no precomputed set/table of powers).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.