6/recent/ticker-posts

# Given an unsorted array of n elements, find if the element k is present in the array or not - Yourcodeway

## Given an unsorted array of n elements, find if the element k is present in the array or not. Complete the findNumber function in the editor below. It has 2 parameters:

1. An array of integers, arr, denoting the elements in the array.
2. An integer, k, denoting the element to be searched in the array
The function must return a string "YES" or "NO" denoting if the element is present in the array or not.

### Solution:

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Solution {

// Complete the findNumber function below.
static String findNumber(List<Integer> arr, int k) {
for (Integer i : arr) {
if (i == k) {
break;
}
}
}

public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

List<String> arrTemp = new ArrayList<>();

IntStream.range(0, arrCount).forEach(i -> {
try {
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});

List<Integer> arr = arrTemp.stream()
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());

String res = findNumber(arr, k);

bufferedWriter.write(res);
bufferedWriter.newLine();