Binary Search
Demo
Star Sum
Amazon Online Assessment
E-Mart Product Ranking
Amazon Online Assessment
Minimum Total Wattage
Amazon Online Assessment
Best Stock Combos
Amazon Online Assessment Subset
Split String
Amazon Online Assessment Array
Find Pairs
Amazon Online Assessment Array
Merge Adjacent Numbers
Amazon Online Assessment Array
Split Array III
Amazon Online Assessment Array
Minimum Number of Swaps
Amazon Online Assessment Array
Collection of Circles
Google Onsite MST
Search Extensible String
New Google Onsite
Maximum Deviation Among All Substrings
Online Assessment String
Maximum Greyness
New Online Assessment Matrix
Separate Pages
New Online Assessment Bit
Shop for Clothes on a Budget
New Online Assessment
Color Palette
Online Assessment Array
Min Appends to Make Subsequence
Online Assessment String
Min Swaps to Partition
New Online Assessment
Minimum Net Price Change
New Online Assessment Intern Array
Channels Maximum Quality
New Online Assessment
Slice Array
New Online Assessment Array
Stock Fluctuation
New Online Assessment Array
Decoding String
New Online Assessment String
Maximum Precipitation
New Online Assessment
Count Reviews II
New Online Assessment
Count Reviews Combinations
New Online Assessment
LRU Browser History
New Online Assessment
Split Array II
Amazon Google New
Load Cargo
Amazon Google New
Split Array
Amazon Google New
Find Bridges In A Graph
Amazon Google MST New
Closest Pair of Molecules
Google Amazon New
Search Matrix
Facebook New
Max Submatrix Sum
Google Facebook New
Cache Hit Ratio
Google Facebook Amazon New
Find Cut Vertices
Google Amazon New
Two Sum Smaller Than Target
Google Amazon New
Can Make Palindrome
Facebook New
Discount Calculator
Amazon New Online Assessment
Max Sink Area
Amazon New
Measure Island Border
Facebook New
Construct Word Using Dice
Google New
Recursive Islands and Lakes
Google Hard New
Packaging Automation
Amazon New Online Assessment
Secret Fruit List
Amazon Online Assessment New
Find Related Products
Amazon Online Assessment New
Remove Duplicated IP Addresses
Amazon Onsite
Optimize Memory Usage
Online Assessment
Min Cost To Add New Roads
Online Assessment
Connect Ropes
Amazon Online Assessment
Pizza Shop
Google Phone
Least Common Ancestor Of Multiple Nodes
Amazon Phone Tree
Remove Duplicated IPv4 Addresses
Amazon Onsite
Fibonacci Base I
Google
Activate Fountain
Twitter Online Assessment
Reaching Point
Twitter Online Assessment
K-Difference
Twitter Online Assessment
Find Critical Nodes
Amazon Online Assessment
Zombie Matrix
Amazon HOT
Data Center Critical Connection
Amazon Online Assessment
Min Cost to Repair Edges (Minimum Spanning Tree II)
Amazon Online Assessment MST Graph
Rose Garden
Google Online Assessment
Minimum Number Of Decreasing Subsequence Partitions
Google Online Assessment Hard DP
Cut Binary Search Tree
Amazon Tree BST Hard LC
Subtree: Maximum Average Node
Amazon Online Assessment Medium Tree
Fill 2D Array
Google Online Assessment
Rearrange String
String
Pickup Coupon
Google Online Assessment
Tree Diameter
Google
Top N Buzzwords
Amazon Online Assessment HOT
Load Balancer
Amazon Online Assessment
Find Substrings
Amazon Online Assessment Hard
Partition String
Amazon Online Assessment String Medium

Twitter OA Activate Fountain

Image placeholder 9899

(This question has been seen in the interviews of the following companies: Twitter)

Activate Fountain

There is a one-dimensional garden of length n. In each position of the n length garden, a fountain has been installed. The fountain at the ith position has a value a[i] (where 1 <= i <= n) that describes the coverage limit of fountain i. A fountain can cover the range from the position max( (i - a[i]), 1) to min ((i + a[i]), n).

For example, if garden length n = 3 and a = {1, 2, 1}, then:

For position 1: a[1] = 1, range = 1 to 2.

For position 2: a[2] = 2, range = 1 to 3.

For position 3: a[3] = 1, range = 2 to 3.

In the beginning, all the fountains are switched off. Determine the minimum number of fountains you need to activate so that whole n length garden will be covered by water. In the example, the 1 fountain at position a[2] covers the whole garden.

Function Description

Complete the function fountainActivation in the editor below. The function must return an integer that denotes the minimum number of fountains that must be activated to cover the entire garden by water.

fountainActivation has the following parameter:

a[a[O)... a[n-1]]: an array of integers

Constraints

• 1 <= n <= 10^5

• 0 <= a[i] <= min( n, 100) (where 1 <= i <= 10^5)

Sample Input

3,1,1,1

Sample Output

1

Explanation

Here, a = {1, 1, 1)

If the 2nd fountain is active, the range from position 1 to 3 will be covered. The total number of fountains needed is 1.


Python


def fountainActivation(fountains):