Array Programs
1. Write a Java program to initialize an array of integers with values {1, 2, 3,
4, 5}.
2. Create a Java program to find the sum of all elements in an integer array.
3. Write a Java method to find the maximum element in an array of
integers.
4. Implement a Java program to reverse an array of integers.
5. Write a Java program to sort an array of integers in ascending order.
6. Create a Java program to find the average of all elements in an integer
array.
7. Implement a Java program to check if an array contains a specific value.
8. Write a Java program to remove duplicate elements from an array of
integers.
9. Create a Java program to find the second largest element in an array of
integers.
10.Implement a Java program to merge two sorted arrays into a single
sorted array.
11.Write a Java program to count the occurrences of a specific element in
an array.
12.Create a Java program to find the minimum element in an array of
integers.
13.Implement a Java program to rotate an array to the right by a given
number of steps.
14.Write a Java program to find the intersection of two arrays.
15.Create a Java program to find the union of two arrays.
16.Implement a Java program to check if two arrays are equal.
17.Write a Java program to find the kth smallest element in an unsorted
array.
18.Create a Java program to find the kth largest element in an unsorted
array.
19.Implement a Java program to find the missing number in a given integer
array of 1 to n.
20.Write a Java program to find the product of all elements in an integer
array.
21.Create a Java program to split an array into two equal sum subarrays.
22.Implement a Java program to find the leaders in an array (elements
which are greater than all elements to their right).
23.Write a Java program to find the contiguous subarray with the largest
sum.
24.Create a Java program to merge overlapping intervals.
25.Implement a Java program to sort an array of 0s, 1s, and 2s.
26.Write a Java program to find the longest increasing subsequence in an
array of integers.
27.Create a Java program to find the equilibrium index of an array (where
the sum of elements before it is equal to the sum of elements after it).
28.Implement a Java program to find the majority element in an array.
29.Write a Java program to move all zeros to the end of an array while
maintaining the relative order of non-zero elements.
30.Create a Java program to find the smallest positive missing number in an
unsorted array.
31.Implement a Java program to rearrange positive and negative numbers
alternatively in an array.
32.Write a Java program to remove an element from a specific index in an
array.
33.Create a Java program to find the maximum product subarray.
34.Implement a Java program to merge k sorted arrays into one sorted
array.
35.Write a Java program to find the median of two sorted arrays.
36.Create a Java program to find the longest subarray with equal number of
0s and 1s.
37.Implement a Java program to find the maximum length bitonic subarray.
38.Write a Java program to move all negative numbers to the beginning of
the array.
39.Create a Java program to find the frequency of each element in a given
array of integers.
40.Implement a Java program to find the triplet with the given sum in an
array.
41.Write a Java program to find the sum of two matrices.
42.Create a Java program to multiply two matrices.
43.Implement a Java program to find the transpose of a matrix.
44.Write a Java program to find the saddle point in a matrix.
45.Create a Java program to perform matrix addition.
46.Implement a Java program to perform matrix subtraction.
47.Write a Java program to check if a matrix is symmetric.
48.Create a Java program to find the sum of each row and column in a
matrix.
49.Implement a Java program to find the product of each row and column in
a matrix.
50.Write a Java program to find the sum of diagonal elements in a matrix.
51.Create a Java program to find the upper triangular matrix of a given
matrix.
52.Implement a Java program to find the lower triangular matrix of a given
matrix.
53.Write a Java program to find the determinant of a 2x2 matrix.
54.Create a Java program to find the rank of a matrix.
55.Implement a Java program to find the inverse of a matrix.
56.Write a Java program to add two matrices using multi-dimensional
arrays.
57.Create a Java program to subtract two matrices using multi-dimensional
arrays.
58.Implement a Java program to multiply two matrices using
multi-dimensional arrays.
59.Write a Java program to find the largest element in a matrix.
60.Create a Java program to find the smallest element in a matrix.
61.Implement a Java program to check if a matrix is sparse.
62.Write a Java program to find the sum of all elements in a sparse matrix.
63.Create a Java program to transpose a sparse matrix.
64.Implement a Java program to add two sparse matrices.
65.Write a Java program to multiply two sparse matrices.
66.Create a Java program to find the sum of the main diagonal elements in a
sparse matrix.
67.Implement a Java program to find the product of the main diagonal
elements in a sparse matrix.
68.Write a Java program to find the sum of the upper diagonal elements in a
sparse matrix.
69.Create a Java program to find the sum of the lower diagonal elements in
a sparse matrix.
70.Implement a Java program to find the product of the upper diagonal
elements in a sparse matrix.
71.Write a Java program to find the product of the lower diagonal elements
in a sparse matrix.
72.Create a Java program to find the sum of the diagonal elements in a
square matrix.
73.Implement a Java program to find the product of the diagonal elements
in a square matrix.
74.Write a Java program to find the sum of all even elements in a matrix.
75.Create a Java program to find the sum of all odd elements in a matrix.
76.Implement a Java program to find the sum of all elements above the
main diagonal in a matrix.
77.Write a Java program to find the sum of all elements below the main
diagonal in a matrix.
78.Create a Java program to find the sum of all elements above the
secondary diagonal in a matrix.
79.Implement a Java program to find the sum of all elements below the
secondary diagonal in a matrix.
80.Write a Java program to find the sum of all elements in each row of a
matrix.
81.Create a Java program to find the sum of all elements in each column of
a matrix.
82.Implement a Java program to find the sum of all elements in each row
above the main diagonal in a matrix.
83.Write a Java program to find the sum of all elements in each column
above the main diagonal in a matrix.
84.Create a Java program to find the sum of all elements in each row below
the main diagonal in a matrix.
85.Implement a Java program to find the sum of all elements in each
column below the main diagonal in a matrix.
86.WAJP to print maximum element based on leftmost digit using
scanner
a. Eg : [12,443,56,23,76,87,98,12,29,19] o/p: 29
87.Given an array of elements of length N,ranging from 0 to N-1.All
elements may not be present in the array.If the element is not present
then there will be -1 present in the array.Rearrange the array such that
A[i] =i and if i is not present,display -1 at that place.
I/p:[-1,-1,6,1,9,3,2,-1,4,-1]
O/p:[-1,1,2,3,4,-1,6,-1,-1,9]
88. WAJP to merge the 2 arrays input a={1,2,3,9,4} b={4,5,6} output
{1,2,3,4,4,5,6}
89. Given an array of integers, find the maximum subarray sum(contiguous).
Example : [1,-2,3,4,-1,2,1,-5,4] Output: 7.
90. WAJP to get the distinct elements in an array and replace distinct
element by zero. i/p:{1,4,3,7,2,1,3,4,8}--> o/p:1,4,3,*,*,1,3,4,*.
91. Given an array of integers nums and an integer target, return indices of
the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and
you may not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
92.
93. WAJP to print maximum element based on leftmost digit using scanner
Eg : [12,443,56,23,76,87,98,12,29,19] o/p: 29
String Programs
1. Write a Java program to concatenate two strings.
2. Write a program to find the length of a string.
3. Write a Java program to compare two strings.
4. Write a program to convert all characters in a string to uppercase.
5. Write a program to convert all characters in a string to lowercase.
6. Write a Java program to reverse a string.
7. Write a program to check if a string is a palindrome.
8. Write a program to find the first non-repeated character in a string.
9. Write a program to count the occurrences of a specific character in a
string.
10. Write a Java program to remove all white spaces from a string.
12. Write a program to remove duplicate characters from a string.
13. Write a Java program to find the longest palindrome in a given string.
14. Write a program to check if two strings are anagrams of each other.
15. Write a Java program to check if a string contains only digits.
16. Write a Java program to replace a specific character in a string.
17. Write a program to split a string into substrings using a delimiter.
18. Write a program to compare two strings lexicographically.
19. Write a Java program to reverse each words in a given sentence.
21. Write a program to capitalize the first letter of each word in a
sentence.
22. Write a program to count the number of vowels and consonants in a
string.
23. Write a Java program to find the second most frequent character in a
string.
24. Write a program to convert a string to a char array.
25. Write a program to check if a string is a rotation of another string.
26. Write a Java program to remove all special characters from a string.
27. Write a program to find the most frequent word in a string.
28. Write a program to remove a specific substring from a string.
29. Write a Java program to find the last occurrence of a character in a
string.
30. Write a program to reverse words in a string without using library
functions.
31. Write a program to check if a string contains only letters.
32. Write a Java program to check if a string ends with a specified suffix.
33. Write a program to find the first repeated character in a string.
34. Write a program to check if a string contains only alphanumeric
characters.
35. Write a Java program to find the common characters between two
strings.
36. Write a program to remove all occurrences of a character from a
string.
37. Write a program to check if a string is empty or null.
38. Write a Java program to find the first occurrence of a character in a
string.
39. Write a program to count the number of words in a string.
40. Write a program to check if a string starts with a specified prefix.
41. Write a Java program to find the difference between two strings.
42. Write a program to remove extra spaces from a string.
43. Write a program to find the shortest palindrome in a given string.
44. Write a Java program to find the first non-repeating character in a
string.
45. Write a program to reverse the order of words in a sentence.
46. Write a program to check if a string contains only whitespace
characters.
47. Write a Java program to find the index of the first non-repeating
character in a string.
48. Write a program to remove all leading and trailing whitespace
characters from a string.
49. Write a program to find the longest substring without repeating
characters.
50. Write a Java program to find the first and last occurrence of a
character in a string.
51. Write a program to check if a string is a valid shuffle of two other
strings.
52. Write a program to find the first character that is not repeated in a
string.
53. Write a Java program to find the smallest substring containing all
characters of another string.
54. Write a program to check if a string contains only printable characters.
55. Write a program to find the first repeating character in a string.
56. Write a Java program to find the longest substring with at most two
distinct characters.
57. Write a program to find the number of occurrences of each word in a
string.
16. Write a program to find the index of a substring in a string.
58. Write a program to remove all non-alphanumeric characters from a
string.
59. Write a Java program to count the number of occurrences of a
substring in a string.
60. Write a program to check if a string is a valid palindrome by ignoring
non-alphanumeric characters.
61. Write a program to find the longest common prefix among an array of
strings.
62. Write a Java program to find the smallest window containing all
characters of a pattern string.
63. Write a program to check if a string contains only ASCII characters.
64. Write a program to find the maximum occurring character in a string.
65. Write a Java program to count the number of occurrences of each
character in a string.
66. Write a program to check if a string is a valid shuffle of two substrings
of another string.
67. Write a program to find the first non-repeating character in a string
using one traversal.
68. Write a Java program to remove all consecutive duplicates from a
string.
69. Write a program to count the number of occurrences of each
character in a string without using collections.
70. Write a program to find the longest substring with unique characters.
71. Write a Java program to find the largest palindrome in a given string.
72. Write a program to count the number of times a substring appears in
another string.
73. Write a program to check if a string contains only ASCII printable
characters.
74. Write a Java program to remove all consecutive duplicates from a
string using recursion.
75. Write a program to check if a string contains only unique characters.
76. Write a program to count the number of times each character appears
in a string.
77. Write a Java program to find the longest common substring between
two strings.
78. Write a program to check if a string is a valid shuffle of two other
strings using recursion.
79. Write a program to find the length of the longest substring without
repeating characters.
80. Write a Java program to find the longest repeating substring in a given
string.
81. Write a program to check if a string contains duplicate characters
within k distance from each other.
82. Write a program to find the length of the longest substring with at
most two distinct characters.
83. Write a Java program to find the longest substring without repeating
characters using a sliding window.
84. Write a program to find the length of the longest common substring
between two strings.
85. Write a program to check if a string can be formed by concatenating a
substring k times.
86. Write a Java program to find the longest common subsequence
between two strings.
87. Write a program to find the length of the longest substring with the
same characters.
88. Write a program to check if a string is a valid shuffle of two other
strings using dynamic programming.
89. Write a Java program to find the length of the shortest common
supersequence of two strings.
90. Write a program to find the length of the longest substring with at
most k distinct characters.
91. Write a program to check if a string can be obtained by rotating
another string by k places.
91. Given an array of integers nums and an integer target, return indices
of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you
may not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
Multi-Dimensional Array:
1. Write a Java program to find the sum of two matrices.
2. Create a Java program to multiply two matrices.
3. Implement a Java program to find the transpose of a matrix.
4. Write a Java program to find the saddle point in a matrix.
5. Create a Java program to perform matrix addition.
6. Implement a Java program to perform matrix subtraction.
7. Write a Java program to check if a matrix is symmetric.
8. Create a Java program to find the sum of each row and column in a
matrix.
9. Implement a Java program to find the product of each row and
column in a matrix.
10. Write a Java program to find the sum of diagonal elements in a
matrix.
11. Create a Java program to find the upper triangular matrix of a
given matrix.
12. Implement a Java program to find the lower triangular matrix of
a given matrix.
13. Write a Java program to find the determinant of a 2x2 matrix.