0% found this document useful (0 votes)
24 views

DSA Lab Exam Questions

The document lists various DSA lab exam questions covering a range of topics including array manipulation, string processing, matrix operations, and algorithm implementation. Each question presents a specific problem to solve, such as finding common elements, sorting arrays, or checking for palindromes. The questions are designed to test the understanding and application of data structures and algorithms.

Uploaded by

tonoydas2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DSA Lab Exam Questions

The document lists various DSA lab exam questions covering a range of topics including array manipulation, string processing, matrix operations, and algorithm implementation. Each question presents a specific problem to solve, such as finding common elements, sorting arrays, or checking for palindromes. The questions are designed to test the understanding and application of data structures and algorithms.

Uploaded by

tonoydas2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DSA Lab Exam Questions

1. Find common elements in three sorted arrays.


2. Find a triplet that sums to a given value.
3. Find whether an array is a subset of another array.
4. First element to occur k times.
5. Reverse words in a given string.
6. Given an expression string exp, write a program to examine whether the pairs
and the orders of “{“, “}”, “(“, “)”, “[“, “]” are correct in the given expression.
7. Given an array of N integers where each value represents the number of
chocolates in a packet. Each packet can have a variable number of chocolates.
There are m students, the task is to distribute chocolate packets such that:
Each student gets one packet.
The difference between the number of chocolates in the packet
with maximum chocolates and the packet with minimum chocolates given to
the students is minimum.
Examples:
Input : arr[] = {7, 3, 2, 4, 9, 12, 56} , m = 3
Output: Minimum Difference is 2
Explanation:
We have seven packets of chocolates and we need to pick three packets for 3
students
If we pick 2, 3 and 4, we get the minimum difference between maximum and
minimum packet sizes.
Input : arr[] = {3, 4, 1, 9, 56, 7, 9, 12} , m = 5
Output: Minimum Difference is 6
Input : arr[] = {12, 4, 7, 9, 2, 23, 25, 41, 30, 40, 28, 42, 30, 44, 48, 43, 50} , m =
7
Output: Minimum Difference is 10
8. Split the array into two parts with equal sum.
9. Check if the array can be divided into pairs whose sum is divisible by k.
10. Merge two sorted arrays.
11. Check if an array is a palindrome.
12. Segregate even and odd nodes in an array.
13. QuickSort code.
14. Sort an array of strings by the number of vowels.
15. Sort an array of strings by their reversed forms.
16. Sort an array of integers by their frequency.
17. Sort an array using merge sort.
18. Sort an array of elements such that all odd numbers appear before even
numbers.
19. Sort an array of names based on their lengths.
20. Check if two strings are anagrams.
21. Print all permutations of a string.
22. Convert a string to lowercase.
23. Count the number of occurrences of a substring in a string.
24. Given a matrix, return its transpose.
25. Rotate a given square matrix by 90 degrees clockwise.
26. Given a matrix where every row is sorted in increasing order from left to right,
and every column is sorted in increasing order from top to bottom, write a
program that searches for a target value.
27. Given an m x n matrix, if an element is 0, set its entire row and column to 0.
28. Given a 2D matrix, return all elements in a diagonal order.
29. WAP to multiply 2 matrices.
30. Given an array nums of n integers, return an array output such that output[i] is
equal to the product of all the elements of nums except nums[i].
31. Given an array where the ith element is the price of a given stock on day i, find
the maximum profit you can achieve. You may complete at most one
transaction.
Example:
Input: [7,1,5,3,6,4]
Output: 5 (buy on day 2 at price 1 and sell on day 5 at price 6)
32. Given a string s, find the longest palindromic substring in s.
Example:
Input: "babad"
Output: "bab" (or "aba")
33. Implement a method to perform basic string compression using the counts of
repeated characters. If the compressed string would not become smaller than
the original string, return the original string.
Example:
Input: "aabcccccaaa"
Output: "a2b1c5a3"
34. Given two strings, determine if they are anagrams of each other.
35. Given a string s, return True if the string can be made a palindrome after
deleting at most one character.
Example:
Input: "abca"
Output: True (You could delete the character "c".)
36. Convert a Roman numeral to an integer.
37. The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of
rows like this: (you may want to display this pattern in a fixed font for better
legibility)
P A H N
APLSIIG
Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number
of rows:
string convert(string s, int numRows);
38. Given a string containing digits from 2-9 inclusive, return all possible letter
combinations that the number could represent. Return the answer in any
order.
A mapping of digits to letters (just like on the telephone buttons) is given
below. Note that 1 does not map to any letters.
Example 1:

Input: digits = "23"


Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2:

Input: digits = ""


Output: []
Example 3:

Input: digits = "2"


Output: ["a","b","c"]
Constraints:

0 <= digits.length <= 4


digits[i] is a digit in the range ['2', '9'].

39. Given a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and
upper cases, more than once.
Example 1:
Input: s = "hello"
Output: "holle"
Example 2:
Input: s = "leetcode"
Output: "leotcede"
40. Given two non-negative integers, num1 and num2 represented as string, return
the sum of num1 and num2 as a string.
Example 1:
Input: num1 = "11", num2 = "123"
Output: "134"
Example 2:
Input: num1 = "456", num2 = "77"
Output: "533"
Example 3:
Input: num1 = "0", num2 = "0"
Output: "0"
41. Insert at beginning of an array.
42. Insert at nth position in an array.

You might also like