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.
Notice that the solution set must not contain duplicate triplets.
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.
Notice that the solution set must not contain duplicate triplets.
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example of a Nested Collection
List<List<String>> nestedList = asList(
asList("one:one"),
asList("two:one", "two:two", "two:three"),
asList("three:one", "three:two", "three:three", "three:four"));
Given an array nums of size n, return the majority element.
The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the
array.
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that
every key of the original BST is changed to the original key plus the sum
of all keys greater than the original key in BST.
What is a greater sum tree:
Given an integer N and two players, A and B are playing a game. On each player’s turn, that player makes a move by subtracting a divisor of current N (which is less than N) from current N, thus forming a new N for the next turn.
Two binary trees are considered leaf-similar if their leaf value sequence is the same.
Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].
Given an integer array nums, return true if the given array is monotonic, or false otherwise.
There is a fence with n posts, each post can be painted with one of the k colors.
find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color.
Note: n and k are non-negative integers.
root1 and root2.Example:Input:Tree 1 Tree 22 3/ \ / \1 4 6 1/ \ \5 2 7Output: Merged tree:5/ \7 5/ \ \5 2 7
Example 1:
- input: s = "abc", t = "ahbgdc"
- Output: true
Example 2:
- Input: s = "axc", t = "ahbgdc"
- Output: false
Examples:Input: N = 3, cost[][3] = {{14, 2, 11}, {11, 14, 5}, {14, 3, 10}}Output: 10Explanation:
- Paint house 0 as blue. Cost = 2.
- Paint house 1 as green. Cost = 5.
- Paint house 2 as blue. Cost = 3.
- Therefore, the total cost = 2 + 5 + 3 = 10.
Input: N = 2, cost[][3] = {{1, 2, 3}, {1, 4, 6}}Output: 3
Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.
Return the shortest such subarray and output its length.
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”
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.
A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.
In a binary tree, a lonely node is a node that is the only child of its parent node. The root of the tree is not lonely because it does not have a parent node.
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or
two steps.
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?
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 security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.