You are using an outdated browser. Please update your browser for a better user experience.

Array Island

arrays

Ahoy there kiddos! Time to take a cool thing and make it a coding problem! You're about to embark out on the seas with your merry crew, except your cartographer is a nerd, and rather than design a normal map, they mapped the seas using a 2D array, where 1's represent land, and 0's represent water....

Find Max

arrays



...

  1. How do we look at elements inside an array?
    • We can use their index. E.g. sizes[0] gives me the first element.
  2. What ways can we look at all the elements in the array?
    • For Loop
    • While Loop
    • Iterators
  3. Think about what variables you might need before writing any code down.
    • We coul...

Find Power Sets

arrays

Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: nums = [1,2,3]

Output: [[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]

In set theory, the power set (or powerset) of a Set A is de...

House Robber

arrays

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have their security systems connected and it will automatically contact the police if two adjac...

Max Volume

arrays

Given n non-negative integers a1, a2, ..., an where each represents a point at coordinate (i, ai) . ‘ n ‘ vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most...

Minimum Window Substring

arrays

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).

Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC"

If there is no such window in S that covers all characters in T, return the empty string.

If there is such wind...

NxN Rotation

arrays

Given an image represented by an NxN matrix of integers, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees.

Optional Constraint: Develop an in place solution!

The rotation can be performed in layers, where you perform a cyclic swap on the edges on each l...

Remove Element

arrays

... Given an array nums, and a target value val, remove all instances of val from nums and return the new length.

For example if nums[] = [3,2,2,4,5] and val = 2, your function should return 3, since it removes two instances of 2

Optional Constraint: Can you develop an in-place solution? (no ad...

Reverse Groups of Letters

arrays

Reverse groups of letters for each word. Avoid reversing any non-letter characters.

Hint:

  • If you would like to, you can assume you have two helper methods for (A) determining if a character is a letter and (B) for reversing a substring.
  • New line characters, white space, tabs, and numerical c...

Search a sorted 2D array

arrays

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

  • Integers in each row are sorted in ascending from left to right.
  • Integers in each column are sorted in ascending from top to bottom.

    Hint: Consider all the different ways you...

Shuffle the Array

arrays

Given the array nums consisting of 2n elements in the form [x1,x2,․․․,xn,y1,y2,․․․,yn].

Return the array in the form [x1,y1,x2,y2,․․․,xn,yn].

Function header: public int[] shuffle(int[] nums, int n) {

}

Shuffle the array offers a variety of different solutions:

"Naive" solution - uses poi...

Smallest Range Covering Elements from K Lists:

arrays

You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.

We define the range [a, b] is smaller than range [c, d] if b - a if b - a == d - c.

Example 1:
Input: nums = [[4,10,15,24,26],[0,9,12,20],[5,18...

String Without AAA or BBB

arrays

Given two integers A and B, return any string S such that:

  • S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters;
  • The substring 'aaa' does not occur in S;
  • The substring 'bbb' does not occur in S.

Example 1:

Input: A = 1, B = 2
Output: "abb"
Explanation: "ab...

Valid Sudoku

arrays

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

  1. Each row must contain the digits 1-9 without repetition.
  2. Each column must contain the digits 1-9 without repetition.
  3. Each of the 9 3x3 sub-boxes of the grid must contain the d...