0%

Reverse String II – LeetCode 541

Problem

Description

Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.

Read more »

Convert BST to Greater Tree – LeetCode 538

Problem

Description

Given 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 sum of all keys greater than the original key in BST.

Read more »

K-diff Pairs in an Array – LeetCode 532

Problem

Description

Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k.

Read more »

Minimum Absolute Difference in BST – LeetCode 530

Problem

Description

Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.

Read more »

Longest Uncommon Subsequence I – LeetCode 521

Problem

Description

Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings.

A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.

The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn’t exist, return -1.

Read more »

Detect Capital – LeetCode 520

Problem

Description

Given a word, you need to judge whether the usage of capitals in it is right or not.

We define the usage of capitals in a word to be right when one of the following cases holds:

  • All letters in this word are capitals, like “USA”.

  • All letters in this word are not capitals, like “leetcode”.

  • Only the first letter in this word is capital if it has more than one letter, like “Google”.

Otherwise, we define that this word doesn’t use capitals in a right way.

Read more »

Perfect Number – LeetCode 507

Problem

Description

We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.

Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not.

Read more »

Relative Ranks – LeetCode 506

Problem

Description

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: “Gold Medal”, “Silver Medal” and “Bronze Medal”.iven two binary strings, return their sum (also a binary string).

Note:

  • N is a positive integer and won’t exceed 10,000.
  • All the scores of athletes are guaranteed to be unique.
Read more »

Base 7 – LeetCode 504

Problem

Description

Given an integer, return its base 7 string representation.

Read more »

Find Mode in Binary Search Tree – LeetCode 501

Problem

Description

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.

Assume a BST is defined as follows:

  • The left subtree of a node contains only nodes with keys less than or equal to the node’s key.

  • The right subtree of a node contains only nodes with keys greater than or equal to the node’s key.

  • Both the left and right subtrees must also be binary search trees.

Read more »