LeetCode Top 150 Interview Questions – Medium Problems with Simple Logic

leetcode top 150 questions easy logic
LeetCode Interview Questions Medium (51–100) with Logic

The LeetCode interview questions medium set (51–100) represents the real difficulty
level asked in most technical interviews.
These problems test your understanding of data structures, recursion, trees, binary search,
and problem-solving patterns
.

Why Medium LeetCode Questions Matter

  • Most real interviews are medium difficulty
  • Tests reasoning, not memorization
  • Builds confidence for advanced problems
  • Frequently asked by product-based companies

BINARY SEARCH (51–60)

51. Binary Search


function search(nums,target){
let l=0,r=nums.length-1;
while(l<=r){
let mid=Math.floor((l+r)/2);
if(nums[mid]===target) return mid;
nums[mid]<target?l=mid+1:r=mid-1;
}
return -1;
}

52. Search in Rotated Sorted Array


function search(nums,target){
let l=0,r=nums.length-1;
while(l<=r){
let mid=Math.floor((l+r)/2);
if(nums[mid]===target) return mid;
if(nums[l]<=nums[mid]){
target>=nums[l]&&target<nums[mid]?r=mid-1:l=mid+1;
}else{
target>nums[mid]&&target<=nums[r]?l=mid+1:r=mid-1;
}
}
return -1;
}

53. Find Minimum in Rotated Sorted Array


function findMin(nums){
let l=0,r=nums.length-1;
while(l<r){
let mid=Math.floor((l+r)/2);
nums[mid]>nums[r]?l=mid+1:r=mid;
}
return nums[l];
}

LINKED LIST (61–70)

61. Linked List Cycle


function hasCycle(head){
let slow=head,fast=head;
while(fast&&fast.next){
slow=slow.next;
fast=fast.next.next;
if(slow===fast) return true;
}
return false;
}

62. Remove Nth Node From End


function removeNthFromEnd(head,n){
let dummy={next:head},fast=dummy,slow=dummy;
for(let i=0;i<=n;i++) fast=fast.next;
while(fast){
fast=fast.next;
slow=slow.next;
}
slow.next=slow.next.next;
return dummy.next;
}

63. Add Two Numbers


function addTwoNumbers(l1,l2){
let dummy=new ListNode(0),cur=dummy,carry=0;
while(l1||l2||carry){
let sum=(l1?.val||0)+(l2?.val||0)+carry;
carry=Math.floor(sum/10);
cur.next=new ListNode(sum%10);
cur=cur.next;
l1=l1?.next;l2=l2?.next;
}
return dummy.next;
}

TREES (71–85)

71. Maximum Depth of Binary Tree


function maxDepth(root){
if(!root) return 0;
return 1+Math.max(maxDepth(root.left),maxDepth(root.right));
}

72. Same Tree


function isSameTree(p,q){
if(!p&&!q) return true;
if(!p||!q||p.val!==q.val) return false;
return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
}

73. Invert Binary Tree


function invertTree(root){
if(!root) return null;
[root.left,root.right]=[invertTree(root.right),invertTree(root.left)];
return root;
}

74. Binary Tree Level Order Traversal


function levelOrder(root){
if(!root) return [];
let res=[],queue=[root];
while(queue.length){
let size=queue.length,level=[];
for(let i=0;i<size;i++){
let node=queue.shift();
level.push(node.val);
node.left&&queue.push(node.left);
node.right&&queue.push(node.right);
}
res.push(level);
}
return res;
}

RECURSION & BACKTRACKING (86–95)

86. Subsets


function subsets(nums){
let res=[];
function backtrack(i,path){
res.push([...path]);
for(let j=i;j<nums.length;j++){
path.push(nums[j]);
backtrack(j+1,path);
path.pop();
}
}
backtrack(0,[]);
return res;
}

87. Permutations


function permute(nums){
let res=[];
function backtrack(path,used){
if(path.length===nums.length){
res.push([...path]);return;
}
for(let i=0;i<nums.length;i++){
if(used[i]) continue;
used[i]=true;
path.push(nums[i]);
backtrack(path,used);
path.pop();used[i]=false;
}
}
backtrack([],Array(nums.length).fill(false));
return res;
}

DYNAMIC PROGRAMMING (96–100)

96. House Robber


function rob(nums){
let prev=0,curr=0;
for(let n of nums){
let temp=Math.max(curr,prev+n);
prev=curr;
curr=temp;
}
return curr;
}

97. Coin Change


function coinChange(coins,amount){
let dp=Array(amount+1).fill(Infinity);
dp[0]=0;
for(let i=1;i<=amount;i++)
for(let c of coins)
if(i-c>=0) dp[i]=Math.min(dp[i],dp[i-c]+1);
return dp[amount]===Infinity?-1:dp[amount];
}

98. Longest Increasing Subsequence


function lengthOfLIS(nums){
let dp=Array(nums.length).fill(1);
for(let i=0;i<nums.length;i++)
for(let j=0;j<i;j++)
if(nums[i]>nums[j])
dp[i]=Math.max(dp[i],dp[j]+1);
return Math.max(...dp);
}

99. Unique Paths


function uniquePaths(m,n){
let dp=Array(n).fill(1);
for(let i=1;i<m;i++)
for(let j=1;j<n;j++)
dp[j]+=dp[j-1];
return dp[n-1];
}

100. Jump Game


function canJump(nums){
let reach=0;
for(let i=0;i<nums.length;i++){
if(i>reach) return false;
reach=Math.max(reach,i+nums[i]);
}
return true;
}

Next Step: Advanced Level (101–150)

You are now interview-ready at medium level.
The final step is mastering advanced LeetCode interview questions (101–150)
covering graphs, advanced DP, greedy, and system-level thinking.

Continue with:

LeetCode Top 150 Interview Questions (101–150) – Advanced Level

Leave a Comment

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