Number of array elements derivable from D after performing certain operations
Difficulty Level : Medium
Last Updated : 09 Jan, 2019 Given an array of N integers and 3 integers D, A and B. The task is to find the number of array elements that we can convert D into by performing the following operations on D:
Add A (+A) Subtract A (-A) Add B (+B) Subtract B (-B) Note: It is allowed to perform any number of operations of any type.
Examples:
Input : arr = {1, 2, 3}, D = 6, A = 3, B = 2
Output : 3 Explanation: We can derive 1 from D by performing (6 - 3(A) - 2(B)) We can derive 2 from D by performing (6 - 2(A) - 2(A)) We can derive 3 from D by performing (6 - 3(A)) Thus, All array elements can be derived from D.
Input : arr = {1, 2, 3}, D = 7, A = 4, B = 2
Output : 2 Explanation: We can derive 1 from D by performing (7 - 4(A) - 2(B)) We can derive 3 from D by performing (7 - 4(A)) Thus, we can derive {1, 3}