Solved the below 3 problem statements using Streams:
1)Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
For example:
Given [10, 15, 3, 7] and k of 17,
return true since 10 + 7 is 17.
2)Given an array of N integers,
You have to find the probability of choosing a random pair(i, j), i < j such that A[i] + A[j] is maximum.
For Example:
Input : A[] = {1, 2, 2, 3}
Output : 0.3333
Explanation :
Here, maximum sum we can get by selecting a pair is 5.
Total number of pairs possible = 6.
Pairs with maximum sum = {2, 3} and {2, 3} = 2.
Probability = 2/6 = 0.3333
3)Given an array of integers, Return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].
Note:The above can be implemented easily without division but the approach shown here has been done without the use of division