KNOWLEDGE INSTITUTE OF TECHNOLOGY, SALEM 637 504
(AN AUTONOMOUS INSTITUTION)
CENTER FOR CAREER DEVELOPMENT AND TRAINING
Problem Solving Practice - Intermediate
1. Next Greater Element
Input:
N = 4, arr[] = [1 3 2 4]
Output:
3 4 4 -1
N = 5, arr[] [6 8 0 1 3]
Output:
8 -1 1 3 -1
2. Given an array A of positive integers. Your task is to find the leaders in the array. An
element of an array is leader if it is greater than or equal to all the elements to its right
side. The rightmost element is always a leader.
Input: arr[] = {16, 17, 4, 3, 5, 2},
Output: 17, 5, 2
3. Given an array Arr of N positive integers and another number X. Determine whether or
not there exist two elements in Arr whose sum is exactly X.
Input:
N = 6, X = 16
Arr[] = {1, 4, 45, 6, 10, 8}
Output: Yes
4. Given two integers dividend and divisor, divide two integers without using multiplication,
division, and mod operator. The integer division should truncate toward zero, which means
losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be
truncated to -2. Return the quotient after dividing dividend by divisor.
Input: dividend = 10, divisor = 3
Output: 3
5. Given an array of strings strs, group the anagrams together. You can return the answer in
any order.
Input:
strs = ["eat","tea","tan","ate","nat","bat"]
Output:
[["bat"],["nat","tan"],["ate","eat","tea"]]
6. 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 = ["flower","flow","flight"]
Output: "fl"
7. *
* * *
* * * * *
* * * * * * *
* * * * * * * * *
8. 1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
9. * * * * * * * * *
* * * * * * *
* * * * *
* * *
*
10. 1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
11. *****
* *
* *
* *
*****
12. *
* *
* *
* * * * *
13. *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
14. Linear Search
15. Binary Search
16. Merge Sort
17. Bubble Sort
18. Heap Sort
19. Selection Sort
20. Insertion Sort