## Carvans Solution

Problem You’re given the maximum speed of N cars in the order they entered the long straight segment of the circuit. Each car prefers to move at its maximum speed. If that’s not possible because of the front car being slow, it might have to lower its speed. It still moves […]

## Ciel and Receipt Solution

ProblemTomya is a girl. She loves Chef Ciel very much. Tomya like a positive integer p, and now she wants to get a receipt of Ciel’s restaurant whose total price is exactly p. Note that the i-th menu has the price 2i-1 (1 ≤ i ≤ 12). Find the minimum number of menus whose total price is […]

## Jump game – LeetCode Solution [Medium]

Jump game (Leetcode) problem statement:You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Jump game – Leetcode Example 1: Input: nums = [2,3,1,1,4] Output: […]

## Determine if two trees are same in C++ – LeetCode Solution [Easy]

Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and each identical node has the same value. Problem statement: https://leetcode.com/problems/same-tree/ Pseudocode 1. Traverse the given binary trees rooted at […]

## Find the Minimum Depth of Binary Tree in C++ – LeetCode Solution [Easy]

Problem StatementGiven a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example 1: Input: root = [3,9,20,null,null,15,7]Output: 2 Find the Minimum Depth of […]

## Convert Sorted Array to Binary Search Tree in C++ – LeetCode Solution [Easy]

Problem Statement Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Example 1: Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10,null,5] Approach This problem […]

## Add Binary numbers in C++ – LeetCode Solution [Easy]

Problem StatementGiven two binary strings a and b containing only 0s and 1s, return their sum as a binary string. Example 1: Input: a = “110”, b = “1” Output: “111” Example 2: Input: a = “1001”, b = “1011” Output: “10100” Add Binary numbers solution Approach This problem could be solved in O(N) time […]

## Rat in the maze

Given a NxN matrix with 0s and 1s. A block with value 0 is a dead end, we cannot use this block to move ahead. While a block with value 1 can be used to travel ahead in the matrix. Now, consider mat[0][0] as the starting point for the rat. We […]

## Fibonacci Numbers in O(logn) [Matrix Exponentiation]

Matrix multiplication can be performed in O(logn) by using matrix exponentiation. It is one of the most used techniques

## 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 StatementMinimum Moves to Equal Array Elements Example 1: Input: nums = [1,2,3] Output: 3 Explanation: [1,2,3] => [2,3,3] => [3,4,3] => […]