Buildings with sunset view Problem

Problem You are given an array representing the heights of neighboring buildings on a city street, from east to west. The city assessor would like you to write an algorithm that returns how many of these buildings have a view of the setting sun, in order to properly value the street. Assumption: Good to clarify with the interviewer, if the heights are equal? For this problem, equal height building don’t obstruct the view, and should be included in answer. ...

Largest Rectangle in Histogram Problem

Problem Given an array of integers heights representing the histogram’s bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram. Examples Example 1: Input: heights = [2,1,5,6,2,3] Output: 10 Explanation: The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units. ...

Next Greater Element 2

Problem Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn’t exist, return -1 for this number. ...

Trapping Rain Water Problem

Problem Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Examples Example 1: ...

Next Greater Element 1

Problem The next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. For each 0 <= i < nums1.length, find the index j such that nums1[i] == nums2[j] and determine the next greater element of nums2[j] in nums2. If there is no next greater element, then the answer for this query is -1. ...

NSR - Nearest Smaller Element to Right of every element

Problem Given an array, print the Next Smaller Element (NSR) for every element. The Next greater element for an element x is the first greater element on the right side of x in the array. The elements for which no greater element exist, print -1. Examples Example 1: Input: {1, 3, 2, 4} Output: {-1, 1, 1, 1} Element Next greater element on the right 1 -1 3 1 2 1 4 1 ...

NGR - Nearest Greater Element to Right of every element

Problem Given an array, print the Next Greater Element (NGE) for every element. The Next greater element for an element x is the first greater element on the right side of x in the array. The elements for which no greater element exist, print -1. Examples Example 1: Input: {1, 3, 2, 4} Output: {3, 4, 4, -1} Element Next greater element on the right 1 3 3 4 2 4 4 -1 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy