Help in this 2 questions!!!! Recently asked in an interview

Revision en1, by wizard_18, 2021-09-09 14:21:21

1) Virat is looking to book hotel rooms for an incoming delegation of engineers. She is Allowed to spend anywhere between B Rupees and C Rupees (Both Inclusive). She needs to book rooms consecutively as delegates would prefer to stay as close as possible.

Virat as been given the pricing of the rooms in the form of a array (A). You need to help virat to find the total no of options available to book like this in the given range.

Note- There is no restriction in no of rooms he can book.( Min 1 or Max Size of the array)

Input Format

First Line contains 3 Integers N,B,c where N is the Size of the array.

Second Line contains N integers denoting the price of t=each rooms available.

Output format

Total No of possible option available for to book the rooms.

Constraints

1 <= N,B,C <= 10^6

Sample Input 0

5 6 8

10 5 1 0 2

Sample Output 0

3

Explanation

[5,1],[5,1,0],[5,1,0,1] are only 3 consecutive options available within the price sum range.

2)We are given an array 'a' of 'N' non-negative elements (eg a1,a2...aN). We can take any two consecutive elements of an array and reduce it by value 1, we can perform this operation as many numbers of times.

We are also given an array 'b' of 'N' non-negative elements (eg b1,b2...bN).It is also made sure that b[i]<=a[i].

Print 'YES' if it is possible to convert array 'a' to array 'b' by using the above operation as many numbers of times. If it is not possible then print 'NO'.

Constraints

1<=N<=1000

0<=A[i]<=10^9

0<=B[i]<=10^9

Input Format

The first line contains T the number of Test Cases.

The second line contains N, No of elements in the array

The Next line contains N space separated positive integers (A1 through An) :

The Next line contains N space separated positive integers (B1 through Bn) :

Output Format

For each test case output YES or NO

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English wizard_18 2021-09-09 14:21:21 1957 Initial revision (published)