In the binary search when we find no>height we should go to the left side as in left there can be height which is less than no greater than height and have low index ??
what is wrong in my code vector leftmostBuildingQueries(vector& heights, vector& queries) { int n = queries.size() ; vector ans( n , -1 ) ; for( int i = 0 ; i < n ; i++ ) { int a = queries[i][0] ; int b = queries[i][1] ; for( int j = max(a,b) ; j < heights.size() ; j++ ) { if( heights[a]
What did Infosys Smoke 🚬 - ruclips.net/user/shortsISgd5Ymdjxs?feature=share
Infosys dev expectation : 🗿
Infosys dev package: 🤡
Aryan Bhai try to do a full dry run of the your code so that the explanation is crystal clear.
bhai ne itna ghumaya ki mera dimag ghum gya
The intuition is on point , great explanation!!!
keep it up and thank you!
How much time it took you to solve this problem?
Thank you teacher, your great explaination helped me a lots
dont use double line reflecting pens..
Keep posting these amazing lectures Aryan
In the binary search when we find no>height we should go to the left side as in left there can be height which is less than no greater than height and have low index ??
12:10 - 12:14 Did i hear that right ? (Hawas 😂)
please dont increase speed of video implicitly in your editing itself
You did not explain the binary search part of the code🙂
priority queue sa solve hoga.
what is wrong in my code
vector leftmostBuildingQueries(vector& heights, vector& queries)
{
int n = queries.size() ;
vector ans( n , -1 ) ;
for( int i = 0 ; i < n ; i++ )
{
int a = queries[i][0] ;
int b = queries[i][1] ;
for( int j = max(a,b) ; j < heights.size() ; j++ )
{
if( heights[a]
My Approach ----> 949 / 952 testcases passed
class Solution {
public:
vector leftmostBuildingQueries(vector& heights, vector& queries) {
int n = heights.size();
// Step 1 : Find the NGE in right
vectorrightMax(n, -1);
stackst;
for(int i = 0; i < n; i++){
while(!st.empty() && heights[st.top()] < heights[i]){
rightMax[st.top()] = i;
st.pop();
}
st.push(i);
}
// Step 2 : Now compute your answer
int m = queries.size();
vectorans(m, -1);
for(int k = 0; k < m; k++){
int i = min(queries[k][0], queries[k][1]);
int j = max(queries[k][0], queries[k][1]);
// Check
if(heights[i] < heights[j] || i == j){
ans[k] = j;
}else{
int temp = j;
while(temp < n && rightMax[temp] != -1 && heights[i] >= heights[rightMax[temp]]){
temp++;
}
if(temp != n || rightMax[temp] != -1) ans[k] = rightMax[temp];
}
}
return ans;
}
};
Noob