Next Greater Element using Stack | Next Greater in Array | Programming Tutorials

Опубликовано: 10 Февраль 2020
на канале: Programming Tutorials
4,400
63

In this tutorial, I have explained multiple approaches to find next greater element in array. Also, how we can find next greater element using stack.

Java code to find first greater element on the right side of every element of an array - https://webrewrite.com/java-program-f...

Given an input array, find the next greater element for every element of an array. The next greater element x is the first greater element on the right side of x in an array. If no next greater element is found then consider -1.

In this tutorial, I have explained how to find next greater element using stack.

For example :

Example 1 -

Input = {4, 2, 6, 8, 1, 0}
Output = {6, 6, 8, -1, -1, -1}


Example 2 -

Input = {7, 8, 1, 4}
Output = {8, -1, 4, -1}


На этой странице сайта вы можете посмотреть видео онлайн Next Greater Element using Stack | Next Greater in Array | Programming Tutorials длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Programming Tutorials 10 Февраль 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 4,400 раз и оно понравилось 63 зрителям. Приятного просмотра!