You are on page 1of 5

WEEKLY ASSESSMENT – 1

Coding question – 1 – 13/14 Test cases Passed


import java.io.*;

import java.util.*;

import java.util.stream.*;

class Result {

public static int sumOfEvenPositiveElements(int[] arr) {

int sum = 0;

boolean found = false;

for (int num : arr) {

if (num > 0 && num % 2 == 0) {

sum += num;

found = true;

if (!found) {

return -1;

if (sum < 0) {

sum = -sum;

return sum;
}

public class Solution {

public static void main(String[] args) throws IOException {

BufferedReader bufferedReader = new BufferedReader(new


InputStreamReader(System.in));

BufferedWriter bufferedWriter = new BufferedWriter(new


FileWriter(System.getenv("OUTPUT_PATH")));

int arrCount = Integer.parseInt(bufferedReader.readLine().trim());

List<Integer> arr = IntStream.range(0, arrCount).mapToObj(i -> {

try {

return bufferedReader.readLine().replaceAll("\\s+$", "");

} catch (IOException ex) {

throw new RuntimeException(ex);

})

.map(String::trim)

.map(Integer::parseInt)

.collect(Collectors.toList());

int[] arr1 = new int[arr.size()];


for (int i = 0; i < arr.size(); i++) {

arr1[i] = arr.get(i);

int result = Result.sumOfEvenPositiveElements(arr1);

bufferedWriter.write(String.valueOf(result));

bufferedWriter.newLine();

bufferedReader.close();

bufferedWriter.close();

}
Coding question – 2 – All test cases Passed
Write the code within the method

class PasswordSanitizer{

public string filter(string[] passwords){

List<string> filteredPasswords = new ArrayList<> ();

for(String password:passwords) {

if(password. length() <5 || password.matches("[0-


9]+")||password.matches("[a-zA-Z]+”)) {

continue;

filteredPasswords.add(password);

return String.join(" “,filteredPasswords);

}
MCQ’s
3. JDK
4. for-each
5. two
6. 115110
7. both integers - floating
8. ((x < 100) && (x > 1) || (x < 0))
9. string
10. break
11. double
12. 11111 , 2222 , 333 , 44 , 5 ,
13. public static final int intCount
14. java.lang
15. 1
16. 1 , 7
17. public

You might also like