Posts

Showing posts with the label revise

510. Inorder Successor in BST II

Image
 https://leetcode.com/problems/inorder-successor-in-bst-ii/description/ Given a  node  in a binary search tree, return  the in-order successor of that node in the BST . If that node has no in-order successor, return  null . The successor of a  node  is the node with the smallest key greater than  node.val . You will have direct access to the node but not to the root of the tree. Each node will have a reference to its parent node. Below is the definition for  Node : class Node { public int val; public Node left; public Node right; public Node parent; }   Example 1: Input: tree = [2,1,3], node = 1 Output: 2 Explanation: 1's in-order successor node is 2. Note that both the node and the return value is of Node type. Example 2: Input: tree = [5,3,6,2,4,null,null,1], node = 6 Output: null Explanation: There is no in-order successor of the current node, so the answer is null.   Constraints: The number of nodes in the ...

1647. Minimum Deletions to Make Character Frequencies Unique

https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/description/ A string  s  is called  good  if there are no two different characters in  s  that have the same  frequency . Given a string  s , return  the  minimum  number of characters you need to delete to make  s   good . The  frequency  of a character in a string is the number of times it appears in the string. For example, in the string  "aab" , the  frequency  of  'a'  is  2 , while the  frequency  of  'b'  is  1 .   Example 1: Input: s = "aab" Output: 0 Explanation: s is already good. Example 2: Input: s = "aaabbbcc" Output: 2 Explanation: You can delete two 'b's resulting in the good string "aaabcc". Another way it to delete one 'b' and one 'c' resulting in the good string "aaabbc". Example 3: Input: s = "ceabaacb" Output: 2 Explanation: You can delete ...

189. Rotate Array

  Given an array, rotate the array to the right by   k   steps, where   k   is non-negative.   Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums = [-1,-100,3,99], k = 2 Output: [3,99,-1,-100] Explanation: rotate 1 steps to the right: [99,-1,-100,3] rotate 2 steps to the right: [3,99,-1,-100]   Constraints: 1 <= nums.length <= 10 5 -2 31 <= nums[i] <= 2 31 - 1 0 <= k <= 10 5   Follow up: Try to come up with as many solutions as you can. There are at least  three  different ways to solve this problem. Could you do it in-place with  O(1)  extra space? ---- Intuition After rotation, elements at the end come in the front reverse full array reverse first k elements reverse remaining elements use helper function Gotcha...