Skip to main content

160 docs tagged with "Google"

View All Tags

01 Matrix

Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.

3Sum

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.

3Sum Closest

Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

Accounts Merge

Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

Add Binary

Given two binary strings a and b, return their sum as a binary string.

Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers...

All Nodes Distance K in Binary Tree

Given the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance k from the target node.

Backspace String Compare

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

Basic Calculator

Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.

Basic Calculator II

Given a string s which represents an expression, evaluate this expression and return its value.

Best Time To Buy And Sell Stock

You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Binary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums...

Binary Tree Maximum Path Sum

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once.

Bus Routes

Return the least number of buses you must take to travel from source to target. Return -1 if it is not possible.

Cheapest Flights Within K Stops

You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.

Climbing Stairs

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Coin Change

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

Combination Sum

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.

Combination Sum II

Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

Combination Sum III

Find all valid combinations of k numbers that sum up to n such that the following conditions are true.

Combination Sum IV

Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

Container With Most Water

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the...

Contains Duplicate

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Counting Bits

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.

Course Schedule

For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, return false.

Course Schedule II

Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.

Daily Temperatures

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature.

Decode Ways

Given a string s containing only digits, return the number of ways to decode it.

Find All Anagrams in a String

Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.

Find All Duplicates In Array

Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

Find K Closest Elements

Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array.

Find Median from Data Stream

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.

Find Peak Element

A peak element is an element that is strictly greater than its neighbors.

First Bad Version

Implement a function to find the first bad version. You should minimize the number of calls to the API.

Flood Fill

An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.

Gas Station

There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Group Anagrams

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

House Robber

Given an integer array nums representing the amount of money of each house, return *the maximum amount of money you can rob tonight without alerting the police.

House Robber II

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle.

Implement Queue using Stacks

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue...

Implement Trie (Prefix Tree)

A trie (pronounced as try) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

Insert Interval

You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti.

Interval List Intersections

You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.

Jump Game

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.

K Closest Points to Origin

Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

Largest Rectangle in Histogram

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.

Letter Combinations of a Phone Number

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

Linked List Cycle

Given head, the head of a linked list, determine if the linked list has a cycle in it.

Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

Longest Palindrome

Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.

Longest Valid Parentheses

Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.

Longest Word in Dictionary

Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.

LRU Cache

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

Maximal Square

Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

Maximum Product Subarray

Given an integer array nums, find a subarray that has the largest product, and return the product.

Maximum Profit in Job Scheduling

You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.

Maximum Subarray

Given an integer array nums, find the subarray which has the largest sum and return its sum.

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

Merge Intervals

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals...

Merge k Sorted Lists

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

Merge Two Binary Trees

Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree.

Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Minimum Height Trees

Among all possible rooted trees, those with minimum height (i.e. min(h)) are called minimum height trees (MHTs).

Minimum Size Subarray Sum

Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.

Minimum Window Substring

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window.

Missing Number

Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

Move Zeroes

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

N-Queens

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

Next Permutation

A permutation of an array of integers is an arrangement of its members into a sequence or linear order.

Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

Number of Islands

Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

Odd Even Linked List

Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.

Pacific Atlantic Water Flow

There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges.

Palindrome Linked List

Given the head of a singly linked list, return true if it is a palindrome or false otherwise.

Palindrome Number

Given an integer x, return true if x is a palindrome, and false otherwise.

Palindrome Pairs

You are given a 0-indexed array of unique strings words. A palindrome pair is a pair of integers (i, j) such that:

Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

Path Sum

Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

Path Sum III

Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.

Permutation in String

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

Permutations

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

Permutations II

Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.

Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n.

Product of Array Except Self

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].

Random Pick with Weight

You need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it.

Remove Linked List Elements

Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

Reorder List

You are given the head of a singly linked-list...

Reorganize String

Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

Reverse Bits

Reverse bits of a given 32 bits unsigned integer.

Reverse Linked List

Given the head of a singly linked list, reverse the list, and return the reversed list.

Reverse Linked List II

Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

Reverse Nodes in k-Group

Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

Rotate Image

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly.

Rotate List

Given the head of a linked list, rotate the list to the right by k places.

Same Tree

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Search a 2D Matrix

Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.

Search in Rotated Sorted Array

Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.

Single Number

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

Sliding Window Maximum

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window.

Sort Colors

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

Sort List

Given the head of a linked list, return the list after sorting it in ascending order.

Spiral Matrix

Given an m x n matrix, return all elements of the matrix in spiral order.

String to Integer (atoi)

Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

Subarray Sum Equals K

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

Subsets

Given an integer array nums of unique elements, return all possible subsets (the power set).

Subsets II

Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

Subtree of Another Tree

Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.

Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

Symmetric Tree

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Task Scheduler

Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task.

Time Based Key-Value Store

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.

Top K Frequent Elements

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Two Sum

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

Unique Paths

There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0])...

Valid Parentheses

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

Word Break

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

Word Ladder

A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that...

Word Search

Given an m x n grid of characters board and a string word, return true if word exists in the grid.

Word Search II

Given an m x n board of characters and a list of strings words, return all words on the board.