+ 3
How to solve this problem using stack?
an array is given of size n. i have to print x+y, n times and i will be incremented on every iteration (1 <= i <= n) where x is the largest number less than i such that array[x] > array[i]. and y is the smallest number greater than i such that array[y]>array[i]. and if x or y doesn't exists then x or y=-1. i need to use stacks so that the program will be efficient enough. i want to understand how can i solve this problem ,so i can solve it on my own.so please just give me an idea how can i do it https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/monk-and-prisoner-of-azkaban/
3 Answers
+ 3
sorry its my fault
this is a link to the original problem
https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/monk-and-prisoner-of-azkaban/
+ 1
Can you explain better? Array its an integer array right? For any iteration you have to find two larger than current array element? If no what? Can you post an simple example? Sorry but i have not understanded
+ 1
Sorry for late... I have readed problem and if i have understanded it good, i think that its not necessary a stack ... You can set 3 var that contain current, previous and next value and update they in any iteration