Loading

Essential DSA Questions Every Student Should Practice (2025)

Published on : August 19, 2025

In 2025, mastering Data Structures and Algorithms (DSA) is essential for anyone preparing for coding interviews, competitive programming, or excelling in computer science. Recruiters from top companies frequently ask questions on arrays, strings, linked lists, stacks, queues, trees, graphs, and dynamic programming. This blog compiles the most frequently asked DSA questions in 2025—helping students and professionals practice effectively, boost problem-solving skills, and get ready for technical interviews with confidence.

1. Two Sum

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

Input: nums = [2,7,11,15], target = 9

Output: [0,1]

Explanation: Because nums[0] + nums[1] == 9.

Practice on LeetCode

2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. Add the two numbers and return the sum as a linked list.

Input: l1 = [2,4,3], l2 = [5,6,4]

Output: [7,0,8]

Explanation: 342 + 465 = 807.

Practice on LeetCode

3. Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n, return the median of the two sorted arrays.

Input: nums1 = [1,3], nums2 = [2]

Output: 2.00000

Explanation: merged array = [1,2,3] and the median is 2.

Practice on LeetCode

4. Search in Rotated Sorted Array

Given a rotated sorted array nums and an integer target, return its index if found, otherwise -1.

Input: nums = [4,5,6,7,0,1,2], target = 0

Output: 4

Input: nums = [4,5,6,7,0,1,2], target = 3

Output: -1

Practice on LeetCode

5. Maximum Subarray

Given an integer array nums, find the subarray with the largest sum, and return its sum.

Input: nums = [-2,1,-3,4,-1,2,1,-5,4]

Output: 6

Explanation: The subarray [4,-1,2,1] has the largest sum = 6.

Practice on LeetCode

6. Best Time to Buy and Sell Stock

You are given an array of prices where prices[i] is the price of a given stock on an ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Input: prices = [7,1,5,3,6,4]

Output: 5

Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6 - 1 = 5.

Practice on LeetCode

7. Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after rain.

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]

Output: 6

Explanation: The above elevation map (black section) is represented by an array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are trapped.

Practice on LeetCode

8. 3Sum

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i ≠ j, i ≠ k, and j ≠ k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.

Input: nums = [-1,0,1,2,-1,-4]

Output: [[-1,-1,2],[-1,0,1]]

Explanation:

  • nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0
  • nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0
  • nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0

The distinct triplets are [-1,0,1] and [-1,-1,2].

Practice on LeetCode

9. Permutations

Given an array of nums of distinct integers, return all the possible permutations. You can return the answer in any order.

Input: nums = [1,2,3]

Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

Practice on LeetCode

10. Word Search

Given an m x n grid of characters board and a string word, return true if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"

Output: true

A B C E
S F C S
A D E E
Practice on LeetCode

11. Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.

Input: s = "abcabcbb"

Output: 3

Explanation: The answer is "abc", with a length of 3.

Practice on LeetCode

12. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".

Input: strs = ["dog","racecar","car"]

Output: ""

Explanation: There is no common prefix among the input strings.

Practice on LeetCode

13. Longest Palindromic Substring

Given a string s, return the longest palindromic substring in s.

Input: s = "babad"

Output: "bab"

Explanation: "aba" is also a valid answer.

Input: s = "cbbd"

Output: "bb"

Practice on LeetCode

14. Valid Parentheses

Given a string s containing just the characters '(', ')', '{', '}', '[', and ']', determine if the input string is valid.

An input string is valid if:

  • Open brackets must be closed by the same type of brackets.
  • Open brackets must be closed in the correct order.
  • Every close bracket has a corresponding open bracket of the same type.

Input: s = "()"

Output: true

Input: s = "()[]{}"

Output: true

Practice on LeetCode

15. Reverse Linked List

Given the head of a singly linked list, reverse the list, and return the reversed list.

Input: head = [1,2,3,4,5]

Output: [5,4,3,2,1]

Original List: 1 2 3 4 5 Reversed List: 5 4 3 2 1
Practice on LeetCode

16. Linked List Cycle

Given the head of a linked list, determine if the linked list has a cycle in it. A cycle exists if some node can be reached again by continuously following the next pointer. pos denotes the index that the tail connects to (not passed as parameter).

Input: head = [3,2,0,-4], pos = 1

Output: true

Explanation: The tail connects to the second node, creating a cycle.

3 2 0 -4
Practice on LeetCode

17. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Input: l1 = [2,4,3], l2 = [5,6,4]

Output: [7,0,8]

Explanation: 342 + 465 = 807.

Practice on LeetCode

18. Merge k Sorted Lists

You are given an array of k linked-lists, each linked list is sorted in ascending order. Merge all the linked lists into one sorted linked list and return it.

Input: lists = [[1,4,5],[1,3,4],[2,6]]

Output: [1,1,2,3,4,4,5,6]

Explanation:
The linked lists are:
[1→4→5], [1→3→4], [2→6]
Merging them into one sorted list: 1→1→2→3→4→4→5→6

Practice on LeetCode

19. Merge k Sorted Lists

You are given an array of k linked-lists, each linked list is sorted in ascending order. Merge all the linked lists into one sorted linked list and return it.

Input: lists = [[1,4,5],[1,3,4],[2,6]]

Output: [1,1,2,3,4,4,5,6]

Explanation:
The linked lists are:
[1→4→5], [1→3→4], [2→6]
Merging them into one sorted list: 1→1→2→3→4→4→5→6

Practice on LeetCode

20. Top K Frequent Elements

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Input: nums = [1,1,1,2,2,3], k = 2

Output: [1,2]

Practice on LeetCode

Want to know more updates?

Stay informed with the latest opportunities and insights - visit our blog!

Muthukumaran Singaravelu
Online

Hi there 👋

How can I help you?

Chat on WhatsApp
WhatsApp Icon