Count of Maximum Solution

Problem Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. Codechef Problem Link Input First line of input contains an integer T, denoting […]

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

Best Time to Buy and Sell Stock [Interview Question]

Problem Statement [LeetCode]You are given an array prices where prices[i] is the price of a given stock on the ith day. You need to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve […]

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

Array Rotation

Array rotation is a problem of changing the order of the elements of the array. Increasing the index of the element by one and changing the index of the last element to 0 and so on. Problem Statement: Given an array arr[] of size n, rotate it by d elements.  Example […]