Professional Documents
Culture Documents
Solving Dsa Interview Questions
Solving Dsa Interview Questions
Solving Dsa Interview Questions
INTERVIEW QUESTIONS
VRITIKA NAIK
•
•
•
•
•
•
•
•
•
•
SUPPLEMENTS – What you need to know!
Linked List
• DFS and BFS Traversals
• Dijkstra’s Algorithm for Shortest Path
• Prim’s and Kruskal’s For Minimum Spanning
Tree
• 0-1 Knapsack Problem
• Subset Sum Problem
• Longest Common Subsequence
• Longest Increasing Subsequence
• Modular Exponentiation
• Sum of Bit Differences among All Pairs
1. Binary Search
2. Search an element in a sorted and rotated
array
3. Bubble Sort
4. Selection Sort
5. Insertion Sort
6. Merge Sort
7. Heap Sort (Binary Heap)
8. Quick Sort
9. Topological Sort
Time to freshen up and refresh concepts!
Go to Kahoot.it and enter the code.
Happy Quizzing!!!
Given a string s representing a roman numeral.
Convert s into an integer.
X = 10
XII = 12
XL = 40
Input: “IV"
Output: 4
Explanation: V-I = 5-1 = 4
int romanToDecimal(string& str)
{
int res = 0;
int value(char r)
for (int i = 0; i < str.length(); i++) {
{
// Getting value of symbol s[i]
if (r == 'I')
int s1 = value(str[i]);
return 1;
if (i + 1 < str.length()) {
if (r == 'V')
// Getting value of symbol s[i+1]
return 5;
int s2 = value(str[i + 1]);
if (r == 'X')
if (s1 >= s2) {
return 10;
res = res + s1;
if (r == 'L')
}
return 50;
else {
if (r == 'C')
res = res + s2 - s1;
return 100;
i++;
if (r == 'D')
}
return 500;
}
if (r == 'M')
else {
return 1000;
res = res + s1;
return -1;
}
}
}
return res;
}
Given an unsorted array of integers, sort the
array into a wave like array. An array ‘arr[0..n-1]’
is sorted in wave form if arr[0] >= arr[1] <=
arr[2] >= arr[3] <= arr[4] >= …..
Examples:
Input: arr[] = {10, 5, 6, 3, 2, 20, 100, 80}
Output: arr[] = {10, 5, 6, 2, 20, 3, 100, 80}
OR {20, 5, 10, 2, 80, 6, 100, 3}
OR any other array that is in wave form
Input:
123
456
789
Output:
741
852
963
Example
Input: [4, 2, 9, 1, 0, 1, 1, 2]
Output: 7
Explanation: You can see the above image in which the
input array is drawn as an elevation map. Here, all the
green boxes represent the number of units of water that
can be trapped after raining.
return res;
}
Know Know your Fundamentals