## Subtract the Product and Sum of Digits of an Integer Leetcode Solution

Problem Statement In this problem, we need to find the difference between the product of digits and the sum of digits of a given positive integer. Example 1234 14 Explanation: Product = 4 * 3 * 2 * 1 = 24 and Sum = 4 + 3 + 2  + …

## Base 7 Leetcode Solution

The problem Base 7 Leetcode Solution, asks us to convert a number into a base 7 number. The given number can be negative or positive until 10 million, in both directions on the number line. The problem seems simple and is a simple conversion of a decimal number into a …

## Power of Four Leetcode Solution

Problem Statement We are given an integer and we have to check if the number is power of 4 or not. A number is power of 4 if there exist an integer a such that,  num= 4^a. Example 16 true 5 false Approach 1 (Brute Force) An obvious way to …

## Check If It Is a Straight Line Leetcode Solution

In this problem, we are given an array of points. This represents a list of x-coordinates and y-coordinates of some points that lie on an X-Y 2-D plane. We need to check if these points form a straight line. Note that there will be at least 2 points in the …

## Pascal’s Triangle II Leetcode Solution

Problem Statement In this problem we have been given Row index(i) of the Pascal Triangle. We have to create a linear array containing the values of the ith row and return it. Row index starts from 0. We know that Pascal’s triangle is a triangle where each number is the …

Problem Statement Given two binary strings a and b, we have to add these two strings and then return the result as a binary string. Binary string are the strings that contains only 0s and 1s. Example a = “11”, b = “1” “100” a = “1010”, b = “1011” “10101” Approach For adding two …

## Roman to Integer Leetcode Solution

In the problem “Roman to Integer”, we are given a string representing some positive integer in its Roman numeral form. Roman numerals are represented by 7 characters that can be converted to integers using the following table: Note: The integer value of the given roman numeral will not exceed or …

## Number of Good Pairs Leetcode Solution

Problem Statement In this problem an array of integers is given and we have to find out the count of total number of good pairs (a[i], a[j]) where a[i]=a[j]. Example nums = [1,2,3,1,1,3] 4 Explanation:   There are 4 good pairs at indices (0,3), (0,4), (3,4), (2,5) . [1,1,1,1] 6 Explanation:  …

## Pow(x, n) Leetcode Solution

The problem “Pow(x, n) Leetcode Solution” states that you are given two numbers, one of which is a floating-point number and another an integer. The integer denotes the exponent and the base is the floating-point number. We are told to find the value after evaluating the exponent over the base. …

## Power of Two Leetcode Solution

We are given an integer and the goal is to check whether the integer is a power of two, that is, it can be represented as some whole power of ‘2‘. Example 16 Yes 13 No Approach A trivial solution can be: Check if all prime factors of the integer …