0

I have the following problem:

Given an array $A$, I need to construct an array $B$ such that $B[i]$ is the minimum $j>i$ such that $A[j]>A[i]$, or Null if no such $j$ exists.

For example, if $A = [23,45,13,10,33]$ then $B = [2,Null,5,5,Null]$.

The algorithm should run in time $\Theta(n)$.

bin
  • 31
  • 3

1 Answers1

2

its next greater element problem
its solvable using stack u can learn it from here (in method 2) for more practice of this useful method u can solve these problems:

Largest Rectangle https://www.hackerrank.com/challenges/largest-rectangle/

And xor Or https://www.hackerrank.com/challenges/and-xor-or

Poisonous Plants https://www.hackerrank.com/challenges/poisonous-plants

196A - Codeforces http://codeforces.com/problemset/problem/196/A

319B - Codeforces http://codeforces.com/problemset/problem/319/B

Minimum Sum http://agc005.contest.atcoder.jp/tasks/agc005_b

these are solvable using #next_greater_element