Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Jim and Pam were sitting in a Park when Pam booked a Uber ride to go back home. The app showed 5 mins of ETA

Jim and Pam were sitting in a Park when Pam booked a Uber ride to go back home. The app showed 5 mins of ETA for the cab to arrive at their location so she thought of sharing a new idea with Jim to tease Dwight next day.
Pam has a magical array A of size N which satisfies 2 conditions:
1. All the Elements in A are greater than or equal to L and smaller than or equal to R, i.e L <= A[i]<= R
2. The sum of all the elements of array A is divisible by 3.
Since the Uber driver came early pam left without sharing the actual array with Jim. So now Jim started thinking how many such magical arrays are possible.
Help Jim by finding how many such arrays are possible for given integers N, L and R as input.
Since the answers may be large, return it with modulo 10^9+7
Constraints:
1< N <=10^6
1<= L <= R <=10^9
Sample:
Input: 213
Output: 3
Explanation: only [1,2],[2,1][3,3] are possible with given N,L,R which satisfies both the conditions
[execution time limit]1 seconds (c)
[memory limit]1 GB
[input] integer n
The size of the array
[input] integer I
Lower limit for each array element
[input] integer r
Upper limit for each array element
[output] integer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago