Week 1: Arrays
1) Max Consecutive Ones
Given a binary array nums, return the maxmum number of consecutives 1’s in the array.
Input: nums = [1,1,0,1,1,1]
Output: 3
Input: nums = [1,0,1,1,0,1]
Output: 2
2) Build Array from Permutations
Given an array nums of n positive integers (0 through n-1), build a new array ans of the same length where ans[i] = nums[nums[i]].
Input: nums = [0,2,1,5,3,4]
Output: [0,1,2,4,5,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
= [0,1,2,4,5,3]
Input: nums = [5,0,1,2,3,4]
Output: [4,5,0,1,2,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
= [4,5,0,1,2,3]
3) Maximum Subarray
Given an integer array (nums), find the contiguous subarray) with the largest sum, and return its sum.
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Input: nums = [1]
Output: 1
Input: nums = [5,4,-1,7,8]
Output: 23
Trial Problems
1) Find epicenter
You are tasked with recovering a lost device in a large open field.
You have access to a function with the signature int search(Location loc). Provided a Location object, the function returns an integer representing the distance away from the signal. Return the Location where search() returns 0
public class Location{
public int x;
public int y;
public Location(int x, int y){
this.x = x;
this.y = y;
}
}
search(new Location(1,1)) // returns 2
search(new Location(3,2)) // returns 1
search(new Location(3,3)) // returns 2
search(new Location(3,1)) // returns 0
[?, ?, ?, ?, ?],
[?, 2, ?, ?, ?],
[?, ?, ?, ?, ?],
[?, 0, 1, 2, ?],
[?, ?, ?, ?, ?]
Output: Location(3,1)

Notes:
- Distance can be diagonal
- Search location is restricted between [0, 4)
- Create a strategy that utilizes as little amount of searches as possible (or don’t)
- Does your strategy change if the search location is unbounded?
2)
Given a char array characters that consists of all lowercase letters, return an int array consisting of the distance from the letter a.
Input: characters = ['a', 'b', 'c', 'd', 'e']
Output: [0, 1, 2, 3, 4]