## DSA: Arrays

### For interviews

The array tracker covers the fundamentals of arrays, a data structure used to store and access multiple elements under a single name. Topics include array creation, accessing elements, modifying array values, array traversal, and common array algorithms. Students will learn to efficiently manipulate and work with arrays to solve programming problems effectively.

Begin by creating a GitHub account.

1. Once you have your account, create a new repository with the name "skill_captain_dsa_arrays ".

2. Inside this repository, organize your daily assignments by creating a separate folder for each day's work. Name each folder "day

3. Make sure to add your assignments to the respective day's folder to keep them organized and easily accessible.

By following these steps, you'll have a GitHub account with a repository specifically designed for your DSA:Arrays assignments, neatly organized by day.

- Day 1

### Concept:

### Assignments:

Given a string s, reverse only all the vowels in the string and return it.

The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.

Example 1:

Input: s = "hello"

Output: "holle"

- Day 2

### Concept:

### Assignments:

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].
The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

You must write an algorithm that runs in O(n) time and without using the division operation.

Example 1:

Input: nums = [1,2,3,4]
Output: [24,12,8,6]

- Day 3

### Concept:

### Assignments:

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

Example 1:

Input: nums = [-1,0,1,2,-1,-4]

Output: [[-1,-1,2],[-1,0,1]]

Explanation:

nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.

nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.

nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.

The distinct triplets are [-1,0,1] and [-1,-1,2].

Notice that the order of the output and the order of the triplets does not matter.

- Day 4

### Concept:

### Assignments:

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.

A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.

Constraints:

m == accounts.length

n == accounts[i].length

1 <= m, n <= 50

1 <= accounts[i][j] <= 100

Example 1:

Input: accounts = [[1,2,3],[3,2,1]]

Output: 6

Explanation:

1st customer has wealth = 1 + 2 + 3 = 6

2nd customer has wealth = 3 + 2 + 1 = 6

Both customers are considered the richest with a wealth of 6 each, so return 6.

Example 2:

Input: accounts = [[1,5],[7,3],[3,5]]

Output: 10

Explanation:

1st customer has wealth = 6

2nd customer has wealth = 10

3rd customer has wealth = 8

The 2nd customer is the richest with a wealth of 10.

- Day 5

### Concept:

### Assignments:

You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.

Constraints:

1 <= flowerbed.length <= 2 * 10^4

flowerbed[i] is 0 or 1.

There are no two adjacent flowers in flowerbed.

0 <= n <= flowerbed.length

Example 1:

Input: flowerbed = [1,0,0,0,1], n = 1

Output: true

Example 2:

Input: flowerbed = [1,0,0,0,1], n = 2

Output: false

- Day 6

### Concept:

### Resources:

### Assignments:

You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:

1. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.

2. Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.

3. Keep repeating the steps again, alternating left to right and right to left, until a single number remains.

Given the integer n, return the last number that remains in arr.

Example:

Input: n = 9

Output: 6

Explanation:

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

arr = [2, 4, 6, 8]

arr = [2, 6]

arr = [6]

- Day 7

### Concept:

### Resources:

### Assignments:

Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.

The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.

Example 1:

Input: citations = [3,0,6,1,5]

Output: 3

Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.

Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.

- Day 8

### Concept:

### Resources:

### Assignments:

You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.

Each plant needs a specific amount of water. You will water the plants in the following way:

Water the plants in order from left to right.

After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.

You cannot refill the watering can early.

You are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.

Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.

Constraints:

n == plants.length

1 <= n <= 1000

1 <= plants[i] <= 10^6

max(plants[i]) <= capacity <= 10^9

Example 1:

Input: plants = [2,2,3,3], capacity = 5

Output: 14

Explanation: Start at the river with a full watering can:

- Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.

- Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.

- Since you cannot completely water plant 2, walk back to the river to refill (2 steps).

- Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.

- Since you cannot completely water plant 3, walk back to the river to refill (3 steps).

- Walk to plant 3 (4 steps) and water it.

Steps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.

Example 2:

Input: plants = [1,1,1,4,2,3], capacity = 4

Output: 30

Explanation: Start at the river with a full watering can:

- Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).

- Water plant 3 (4 steps). Return to river (4 steps).

- Water plant 4 (5 steps). Return to river (5 steps).

- Water plant 5 (6 steps).

Steps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.

Example 3:

Input: plants = [7,7,7,7,7,7,7], capacity = 8

Output: 49

Explanation: You have to refill before watering each plant.

Steps needed = 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 = 49.