Stack & Queue 2: Next greater element | Must Do Coding Questions | GeeksForGeeks

Published: 29 July 2021
on channel: Krishna Teaches
911
18

This video contains Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …
from geeksforgeeks platform.

website link:
https://www.geeksforgeeks.org/must-do...

Topics covered in this video series are:
1.Arrays
   • 1.1 ARRAYS | Must Do Coding Questions  
2.String
   • 1.2 STRING | Must Do Coding Questions  
3.Linked List
   • 1.3 LINKED LIST | Must Do Coding Questions  
4.Stack and Queue
5.Tree and BST
6.Heap
7.Recursion
8.Hashing
9.Graph
10.Greedy
11.Dynamic Programming
12.Divide and Conquer
13.Backtracking
14.Bit Magic

Stack and Queue:
2: Next Greater Element:
Given an array arr[ ] of size N having distinct elements, the task is to find the next greater element for each element of the array in order of their appearance in the array.
Next greater element of an element in the array is the nearest element on the right which is greater than the current element.
If there does not exist next greater of current element, then next greater element for current element is -1. For example, next greater of the last element is always -1.

Example 1:
Input:
N = 4, arr[] = [1 3 2 4]
Output:
3 4 4 -1
Explanation:
In the array, the next larger element to 1 is 3 , 3 is 4 , 2 is 4 and for 4 ? since it doesn't exist, it is -1.

Example 2:
Input:
N = 5, arr[] [6 8 0 1 3]
Output:
8 -1 1 3 -1
Explanation:
In the array, the next larger element to 6 is 8, for 8 there is no larger elements hence it is -1, for 0 it is 1 , for 1 it is 3 and then for 3 there is no larger element on right and hence -1.

Code Link:
https://github.com/krishna-gavas/Comp...

Intro Music :
   • Video  p


On this page of the site you can watch the video online Stack & Queue 2: Next greater element | Must Do Coding Questions | GeeksForGeeks with a duration of hours minute second in good quality, which was uploaded by the user Krishna Teaches 29 July 2021, share the link with friends and acquaintances, this video has already been watched 911 times on youtube and it was liked by 18 viewers. Enjoy your viewing!