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: […]

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 […]