Skip to main content

Command Palette

Search for a command to run...

Power of Four

Published
1 min read
Power of Four
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

Given an integer n, return true if it is a power of four. Otherwise, return false.

An integer n is a power of four, if there exists an integer x such that n == 4<sup>x</sup>.

LeetCode Problem - 342: Link | Click Here

class Solution {
    // Method to check if a given number is a power of four
    public boolean isPowerOfFour(int n) {

        // Check if n is 1, as 4^0 is 1, and 1 is a power of four
        if(n == 1) {
            return true;
        }
        // Check if n is 0, as 0 is not a power of four
        else if(n == 0) {
            return false;
        }

        // Check if n is divisible by 4; if not, it is not a power of four
        if(n % 4 != 0) {
            return false;
        }

        /*
        The recursive solution to check if n/4 is a power of four.
        This reduces the problem by dividing n by 4 in each recursive call.
        */


        /*
        This solution is creates time complexity
        int check = 1;
        while(check < n){
            check *= 4;
        }
        */

        return isPowerOfFour(n / 4);
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.