TCS Compilation
TCS Compilation
QUESTIONS YouTube
Solution
1. Find the smallest number in an array
2. Find the largest number in an array
3. Find the second smallest and second largest element in an
array
4. Reverse a given array
5. Count the frequency of each element in an array
6. Rearrange the array in increasing-decreasing order
7. Calculate the sum of the elements of the array
8. Rotate an array by K elements - Block Swap Algorithm
9. Find the average of all elements in an array
10. Find the median of the given array
11. Remove duplicates from a sorted array
12. Remove duplicates from an unsorted array
13. Add an element in an array
14. Find all repeating elements in an array
15. Find all non-repeating elements in an array
16. Find all symmetric pairs in an array
17. Find the maximum product subarray in an array
18. Replace each element of the array by its rank in the array
19. Sort the elements of an array by frequency
20. Rotate the elements of an array (left and right)
21. Find the equilibrium index of an array
22. Find the circular rotation of an array by K positions
23. Sort an array according to the order defined by another array
24. Search for an element in an array
25. Check if an array is a subset of another array or not
26. Check if a given string is palindrome or not.
27. Count number of vowels, consonants, spaces in a string.
28. Find the ASCII value of a character.
29. Remove all vowels from the string.
30. Remove spaces from a string.
31. Remove characters from a string except alphabets.
32. Reverse a string.
33. Remove brackets from an algebraic expression.
34. Sum of the numbers in a string.
35. Capitalize first and last character of each word.
36. Calculate frequency of characters in a string.
37. Find non-repeating characters of a string.
38. Check if two strings are anagrams of each other.
39. Count common sub-sequence in two strings.
40. Check if two strings match where one string contains wildcard
characters.
41. Return maximum occurring character in the input string.
42. Remove all duplicates from the input string.
43. Print all the duplicates in the input string.
18. Replace each element of the array by its rank in the array
java
java
if (str.charAt(left) != str.charAt(right)) {
return false;
left++;
right--;
return true;
java
str = str.toLowerCase();
spaces++;
else consonants++;
countElements(str);
java
}
public static void main(String[] args) {
char ch = 'A';
System.out.println(getAsciiValue(ch)); // Output: 65
java
java
}
public static void main(String[] args) {
java
7. Reverse a String
java
java
System.out.println(removeBrackets(str)); // Output: 3 + 2 * 4 + 5
java
if (Character.isDigit(ch)) {
temp += ch;
} else {
if (!temp.isEmpty()) {
sum += Integer.parseInt(temp);
temp = "";
if (!temp.isEmpty()) {
sum += Integer.parseInt(temp);
return sum;
java
if (word.length() == 1) {
result.append(word.toUpperCase()).append(" ");
} else {
result.append(word.substring(0, 1).toUpperCase())
.append(word.substring(word.length() - 1).toUpperCase())
.append(" ");
return result.toString().trim();
java
import java.util.HashMap;
import java.util.Map;
System.out.println(frequencyMap);
java
import java.util.LinkedHashMap;
import java.util.Map;
System.out.println("Non-repeating characters:");
findNonRepeating(str); // Output: h e w r d
java
import java.util.Arrays;
Arrays.sort(arr1);
Arrays.sort(arr2);
java
} else {
return dp[str1.length()][str2.length()];
}
}
15. Check if two strings match where one string contains wildcard characters
java
dp[0][0] = true;
return dp[m][n];
java
import java.util.HashMap;
import java.util.Map;
int maxCount = 0;
maxChar = entry.getKey();
maxCount = entry.getValue();
return maxChar;
}
public static void main(String[] args) {
System.out.println(maxOccurringChar(str)); // Output: s
java
if (!seen[ch]) {
result.append(ch);
seen[ch] = true;
return result.toString();
java
import java.util.HashMap;
import java.util.Map;
System.out.println("Duplicate characters:");
if (entry.getValue() > 1) {