Posts

Showing posts from December, 2022

2101. Detonate the Maximum Bombs

Image
 https://leetcode.com/problems/detonate-the-maximum-bombs/description/ You are given a list of bombs. The  range  of a bomb is defined as the area where its effect can be felt. This area is in the shape of a  circle  with the center as the location of the bomb. The bombs are represented by a  0-indexed  2D integer array  bombs  where  bombs[i] = [x i , y i , r i ] .  x i  and  y i  denote the X-coordinate and Y-coordinate of the location of the  i th  bomb, whereas  r i  denotes the  radius  of its range. You may choose to detonate a  single  bomb. When a bomb is detonated, it will detonate  all bombs  that lie in its range. These bombs will further detonate the bombs that lie in their ranges. Given the list of  bombs , return  the  maximum  number of bombs that can be detonated if you are allowed to detonate  only one  bomb .   Example 1: Input: bombs = [[2,1,3],[6,1,4]] Output: 2 Explanation: The above figure shows the positions and ranges of the 2 bombs. If we detonate the left b

Kth Largest in BST

 https://workat.tech/problem-solving/practice/kth-largest-element-bst Given the root node of a binary search tree and a number  k , find out the k th  largest element (1-indexed) in the BST. Note: You can assume that k <= number of nodes. Testing Input Format The first line contains an integer  T  denoting the number of test cases. For each test case, the input has 2 lines: The first line contains an integer  n  denoting the number of nodes in the tree (including the NULL nodes). The second line contains  n  space-separated integers that will form the binary tree. The integers follow level order traversal of the tree where -1 indicates a NULL node. The third line contains an integer  k . Output Format For each test case, the output contains an integer with the value of the k th  largest element in BST. Sample Input 4 9 2 1 3 -1 -1 -1 5 4 7 4 7 6 3 21 -1 -1 -1 89 1 12 8 3 9 -1 4 -1 10 -1 -1 -1 12 11 7 4 28 14 -1 11 2 Expected Output 3 89 3 14 1 <= T <= 10 1 <= n <= 10 5 1

Inorder Predecessor of Node in BST

Image
 https://workat.tech/problem-solving/practice/inorder-predecessor-bst The inorder predecessor of a node  p  is the node  q  that comes just before  p  in the binary tree's inorder traversal. Given the root node of a binary search tree and the node  p , find the inorder predecessor of node  p . If it does not exist, return  null . Testing Input Format The first line contains an integer  T  denoting the number of test cases. For each test case, the input has 2 lines: The first line contains an integer  n  denoting the number of nodes in the tree (including the NULL nodes). The second line contains  n  space-separated integers that will form the binary tree. The integers follow level order traversal of the tree where -1 indicates a NULL node. The third line contains an integer denoting the 0-based index of p in the above list. Output Format For each test case, the output contains an integer with the value of the inorder predecessor. In case the predecessor doesn't exist the value

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 tree is in the range  [1, 10 4 ] . -10 5 <= No

Package Boxing

https://app.codesignal.com/company-challenges/jet/SrM76w6eoxioTMiCK Before delivery, all orders at Jet are packed into boxes to protect them from damage. Consider a package  pkg  of a given size that needs to be packed into a box chosen from a list of available  boxes . The package should fit inside the box, keeping in mind that the size of the package should not exceed the size of the box in any dimension (note that the package can be rotated to fit and it can be positioned upside down). For the sake of efficiency, among the available boxes that fit, the one with smallest volume should be chosen. Given a package  pkg  and available  boxes , find the 0-based index of the smallest-by-volume box such that the package fits inside it, or return  -1  if there is no such box. Example For  pkg = [4, 2, 5]  and  boxes = [[4, 3, 5], [5, 2, 5]] , the output should be solution(pkg, boxes) = 1 . The package fits into both boxes, but the volume of the first one ( 4 * 3 * 5 = 60 ) is greater than th