LeetCode Top 150 Interview Questions – Advanceed Problems with Simple Logic

leetcode top 150 questions easy logic
LeetCode Advanced Interview Questions (101–150) with Logic

The LeetCode advanced interview questions (101–150) are designed for
senior engineers, product-based companies, and high-bar technical interviews.
These problems focus on graphs, advanced dynamic programming, greedy strategies,
and system-level thinking.

Why Advanced LeetCode Problems Matter

  • Asked by FAANG & top startups
  • Tests optimization and edge cases
  • Requires deep DSA understanding
  • Separates good candidates from great ones

GRAPHS (101–115)

101. Number of Islands


function numIslands(grid){
let count=0;
function dfs(i,j){
if(i<0||j<0||i>=grid.length||j>=grid[0].length||grid[i][j]==='0') return;
grid[i][j]='0';
dfs(i+1,j);dfs(i-1,j);dfs(i,j+1);dfs(i,j-1);
}
for(let i=0;i<grid.length;i++)
for(let j=0;j<grid[0].length;j++)
if(grid[i][j]==='1'){count++;dfs(i,j);}
return count;
}

102. Clone Graph


function cloneGraph(node,map=new Map()){
if(!node) return null;
if(map.has(node)) return map.get(node);
let copy=new Node(node.val);
map.set(node,copy);
for(let n of node.neighbors)
copy.neighbors.push(cloneGraph(n,map));
return copy;
}

103. Course Schedule


function canFinish(numCourses,prereq){
let graph=Array.from({length:numCourses},()=>[]);
let indeg=Array(numCourses).fill(0);
for(let [a,b] of prereq){graph[b].push(a);indeg[a]++;}
let q=[];
indeg.forEach((v,i)=>v===0&&q.push(i));
let count=0;
while(q.length){
let n=q.shift();count++;
for(let nei of graph[n])
if(--indeg[nei]===0) q.push(nei);
}
return count===numCourses;
}

DYNAMIC PROGRAMMING (116–130)

116. Longest Common Subsequence


function lcs(text1,text2){
let m=text1.length,n=text2.length;
let dp=Array.from({length:m+1},()=>Array(n+1).fill(0));
for(let i=1;i<=m;i++)
for(let j=1;j<=n;j++)
dp[i][j]=text1[i-1]===text2[j-1]
?dp[i-1][j-1]+1
:Math.max(dp[i-1][j],dp[i][j-1]);
return dp[m][n];
}

117. Edit Distance


function minDistance(a,b){
let m=a.length,n=b.length;
let dp=Array.from({length:m+1},()=>Array(n+1).fill(0));
for(let i=0;i<=m;i++) dp[i][0]=i;
for(let j=0;j<=n;j++) dp[0][j]=j;
for(let i=1;i<=m;i++)
for(let j=1;j<=n;j++)
dp[i][j]=a[i-1]===b[j-1]
?dp[i-1][j-1]
:1+Math.min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]);
return dp[m][n];
}

118. Word Break


function wordBreak(s,dict){
let set=new Set(dict);
let dp=Array(s.length+1).fill(false);
dp[0]=true;
for(let i=1;i<=s.length;i++)
for(let j=0;j<i;j++)
if(dp[j]&&set.has(s.slice(j,i))){dp[i]=true;break;}
return dp[s.length];
}

GREEDY (131–140)

131. Gas Station


function canCompleteCircuit(gas,cost){
let total=0,tank=0,start=0;
for(let i=0;i<gas.length;i++){
total+=gas[i]-cost[i];
tank+=gas[i]-cost[i];
if(tank<0){start=i+1;tank=0;}
}
return total>=0?start:-1;
}

132. Jump Game II


function jump(nums){
let jumps=0,end=0,farthest=0;
for(let i=0;i<nums.length-1;i++){
farthest=Math.max(farthest,i+nums[i]);
if(i===end){
jumps++;
end=farthest;
}
}
return jumps;
}

BACKTRACKING (141–145)

141. N-Queens


function solveNQueens(n){
let res=[],cols=new Set(),d1=new Set(),d2=new Set();
function backtrack(r,board){
if(r===n){res.push([...board]);return;}
for(let c=0;c<n;c++){
if(cols.has(c)||d1.has(r-c)||d2.has(r+c)) continue;
cols.add(c);d1.add(r-c);d2.add(r+c);
board.push('.'.repeat(c)+'Q'+'.'.repeat(n-c-1));
backtrack(r+1,board);
board.pop();cols.delete(c);d1.delete(r-c);d2.delete(r+c);
}
}
backtrack(0,[]);
return res;
}

ADVANCED TREES & MATH (146–150)

146. Serialize and Deserialize Binary Tree


function serialize(root){
let res=[];
function dfs(node){
if(!node){res.push('null');return;}
res.push(node.val);
dfs(node.left);dfs(node.right);
}
dfs(root);
return res.join(',');
}

147. Kth Smallest in BST


function kthSmallest(root,k){
let stack=[];
while(true){
while(root){stack.push(root);root=root.left;}
root=stack.pop();
if(--k===0) return root.val;
root=root.right;
}
}

148. Pow(x, n)


function myPow(x,n){
if(n===0) return 1;
let half=myPow(x,Math.floor(n/2));
return n%2===0?half*half:(n>0?half*half*x:half*half/x);
}

149. Sqrt(x)


function mySqrt(x){
let l=0,r=x;
while(l<=r){
let m=Math.floor((l+r)/2);
if(m*m<=x) l=m+1;
else r=m-1;
}
return r;
}

150. Evaluate Reverse Polish Notation


function evalRPN(tokens){
let stack=[];
for(let t of tokens){
if(!isNaN(t)) stack.push(Number(t));
else{
let b=stack.pop(),a=stack.pop();
if(t==='+') stack.push(a+b);
if(t==='-') stack.push(a-b);
if(t==='*') stack.push(a*b);
if(t==='/') stack.push(Math.trunc(a/b));
}
}
return stack[0];
}

Congratulations

You have now completed the LeetCode Top 150 Interview Questions
(Easy → Medium → Advanced).
This puts you in a strong position for high-level technical interviews.

Revisit:
Easy (1–50) |
Medium (51–100)

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version