[Geeks for Geeks] Circular tour

Circular tour

Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.

  1. The amount of petrol that every petrol pump has.
  2. Distance from that petrol pump to the next petrol pump.

Find a starting point where the truck can start to get through the complete circle without exhausting its petrol in between.

Note : Assume for 1 litre petrol, the truck can go 1 unit of distance.

Read more
[Geeks for Geeks] Stock buy and sell

Stock buy and sell

The cost of stock on each day is given in an array A[] of size N. Find all the days on which you buy and sell the stock so that in between those days your profit is maximum.
Note: There may be multiple possible solutions. Return any one of them. Any correct solution will result in an output of 1, whereas wrong solutions will result in an output of 0.

Read more
[Geeks for Geeks] Maximum of all subarrays of size k

Maximum of all subarrays of size k

Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K.

Read more
[Geeks for Geeks] Maximum Rectangular Area in a Histogram

Maximum Rectangular Area in a Histogram

Find the largest rectangular area possible in a given histogram where the largest rectangle can be made of a number of contiguous bars. For simplicity, assume that all bars have the same width and the width is 1 unit, there will be N bars height of each bar will be given by the array arr.

Read more
[Geeks for Geeks] k-th smallest element in BST

k-th smallest element in BST

Given a BST and an integer K. Find the Kth Smallest element in the BST.

Read more
[Geeks for Geeks] Longest Palindrome in a String

Longest Palindrome in a String

Given a string S, find the longest palindromic substring in S. Substring of string S: S[ i . . . . j ] where 0 ≤ i ≤ j < len(S). Palindrome string: A string which reads the same backwards. More formally, S is palindrome if reverse(S) = S. Incase of conflict, return the substring which occurs first ( with the least starting index).

Read more
[Geeks for Geeks] Smallest window in a string containing all the characters of another string

Smallest window in a string containing all the characters of another string

Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return “-1” in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.

Read more
[LeetCode] Percentage of Letter in String

2278. Percentage of Letter in String

Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.

Read more
[LeetCode] Maximum Bags With Full Capacity of Rocks

2279. Maximum Bags With Full Capacity of Rocks

You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.

Return the maximum number of bags that could have full capacity after placing the additional rocks in some bags.

Read more
[LeetCode] Minimum Lines to Represent a Line Chart

2280. Minimum Lines to Represent a Line Chart

You are given a 2D integer array stockPrices where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:

Read more