Arranging Cupcakes Solution

ProblemOn the day of the party, the Chef was over-seeing all the food arrangements as well, ensuring that every item was in its designated position. The host was satisfied with everything except the cupcakes. He noticed they were arranged neatly in the shape of a rectangle. He asks the Chef to […]

Is Fibo Solution

ProblemYou are given an integer, N. Write a program to determine if N is an element of the Fibonacci sequence.The first few elements of the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13…. Hackerrank Problem Link Input The first line of input contains a single integer T, number of test cases. T lines […]

Rectangular Game Solution

Problem You are given an infinite 2d grid with the bottom left cell referenced as (1,1). All the cells contain a value of zero initially. Let’s play a game? The game consists of N steps wherein each step you are given two integers a and b. The value of each of the cells in the coordinate […]

Pascal’s Triangle

In mathematics, Pascal’s triangle is a triangular array of the binomial coefficients. It can also be viewed as: each number in Pascal’s triangle is the sum of the two numbers directly above it as shown: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 […]

Minimum number of moves to equal array elements – LeetCode Solution [Medium]

Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n – 1 elements of the array by 1. Problem Statement Example 1: Input: nums = [1,2,3] Output: 3 Explanation: [1,2,3] => [2,3,3] => [3,4,3] => [4,4,4] Minimum number of […]

Matrix-chain multiplication

We are given a sequence (chain) (M1, M2, M3…Mn) of n matrices to be multiplied and we need to find the most efficient way to multiply these matrices together. Now, if the chain of matrices is M1*M2*M3*M4, then it could be evaluated in various distinct ways without affecting the final product: (M1(M2(M3*M4))) […]