319 challenges in the catalogue. Browse freely; sign in to open the editor and submit.
Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. The length of…
Sign in to solveGiven an m x n matrix, return all elements of the matrix in spiral order. Example 1: Example 2: m == matrix.length n == matrix[i].length 1 <= m, n <= 10 -100 <= matrix[i][j] <= 100
Sign in to solveWrite a solution to find the rank of the scores. The ranking should be calculated according to the following rules: The scores should be ranked from the highest to the lowest. If there is a tie between two scores, both should have the same…
Sign in to solveGiven an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. Example 1: Example 2: m == board.length n ==…
Sign in to solveGiven strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. An interleaving of two strings s and t is a configuration where s and t are divided into n and m substrings respectively, such that the interleaving…
Sign in to solveGiven the root of a complete binary tree, return the number of the nodes in the tree. According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far…
Sign in to solveYou are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a…
Sign in to solveGiven the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node…
Sign in to solveDesign a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed. Implement the Twitter class: Twitter() Initializes your twitter object.…
Sign in to solveYou are given an m x n grid rooms initialized with these three possible values: -1 A wall or an obstacle. 0 A gate. INF Infinity means an empty room. We use the value 2^31 - 1 = 2147483647 to represent INF as you may assume that the…
Sign in to solveGiven two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0…
Sign in to solveYou are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have…
Sign in to solve