Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Power Of Numbers

Medium Acceptance 20.22% Points 30.00

Given a number n, compute the value of n raised to the power of its reverse.

Note: The result will always fit within the range of a 32-bit signed integer.

Examples
Example 1

Example 1

Input: n = 3

Output: 27

Explanation: The reverse of 3 is 3, and 3^3 = 27.

Example 2

Example 2

Input: n = 5

Output: 25

Explanation: The reverse of 5 is 5, and 5^5=25.

Hints
Hint 1
Expected Time Complexity: O(log n)
Hint 2
Expected Auxiliary Space: O(log n)
Constraints
  • 1 <= n <= 10
Companies
Samsung Walmart
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions