
2 Years Java FullStack Developer Screening Assessment
#assessment #java #2years
Posted by TechElliptica at 01 May 2025 ( Day(s) Before)
Remove vowel (a,e,i,o,u,A,E,I,O,U) from string from java?
Example:
Input String : abaciEohjUuOutput String : bchj
public class VowelAssignment {
public static void main(String[] args) {
String input = "ThisIsVowelRemovalProgram";
String vowelRegularExpressionString = "[aeiouAEIOU]";
input = input.replaceAll(vowelRegularExpressionString,"");
System.out.println(input);
}
}
Time Complexity : O(n)
Space Complexity : O(n)
Find number of Occurrences of substring in a given string ?
Example:
inputString = "ababcabcab";
patterntoCheck = "ab";
ababcabcab
Number of occurrences: 4
public class OccurrenceAssignment {
public static void main(String[] args) {
String inputString = "ababcabcab";
String patternToCheck ="ab";
int index = 0;
int total = 0;
boolean found = true;
while(found){
int indexOf = inputString.indexOf(patternToCheck,index);
if(indexOf != -1){
total++;
index = indexOf + patternToCheck.length();
}else{
found = false;
}
}
System.out.println(total);
}
}
Sort and array and then find alternate index array?
Example:
input = [1,4,2,5,8,3,2]Step 1 - Sort array = [1,2,2,3,4,5,8]Output - [1,2,4,8] - every alternate index (9) and then print that array
public class TechEllipticaAlternateArray {
public static void main(String[] args) {
int[] input = {1, 4, 2, 5, 8, 3, 2};
Arrays.sort(input);
int[] result = new int[(input.length + 1) / 2];
int j = 0;
for (int i = 0; i < input.length; i += 2) {
result[j++] = input[i];
}
System.out.print("Alternate index array: "+Arrays.toString(result));
}
}
Follow Us
Course
Copyright
Services

