Given an m x n matrix, return all elements of the matrix in spiral order.
Example 1:
1 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] |
Example 2:
1 | Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] |
Given an m x n matrix, return all elements of the matrix in spiral order.
Example 1:
1 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] |
Example 2:
1 | Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] |
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Example 1:
1 | Input: nums = [-2,1,-3,4,-1,2,1,-5,4] |
Example 2:
1 | Input: nums = [1] |
Example 3:
1 | Input: nums = [5,4,-1,7,8] |
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
1 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] |
Example 2:
1 | Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] |
Example 3:
1 | Input: matrix = [[1]] |
Example 4:
1 | Input: matrix = [[1,2],[3,4]] |
Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.
The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.
It is guaranteed that the number of unique combinations that sum up to target is less than 150 combinations for the given input.
Example 1:
1 | Input: candidates = [2,3,6,7], target = 7 |
Example 2:
1 | Input: candidates = [2,3,5], target = 8 |
Example 3:
1 | Input: candidates = [2], target = 1 |
Example 4:
1 | Input: candidates = [1], target = 1 |
Example 5:
1 | Input: candidates = [1], target = 2 |