Permutations of Array 1

Problem Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. OR Given a collection of numbers, return all possible permutations. Examples Example 1: nums = [1,2,3] Output: [ [1,2,3] [1,3,2] [2,1,3] [2,3,1] [3,1,2] [3,2,1] ] ...

Integer To Roman Problem

Problem Roman numerals Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Examples Example 1: Input: num = 3 Output: "III" Explanation: 3 is represented as 3 ones. Example 2: Input: num = 58 Output: "LVIII" Explanation: L = 50, V = 5, III = 3. ...

Roman To Integer Problem

Problem Roman numerals Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Examples Example 1: Input: s = "III" Output: 3 Explanation: III = 3. Example 2: Input: s = "LVIII" Output: 58 Explanation: L = 50, V= 5, III = 3. ...

Add Two Numbers represented as Linked List in Reversed Order

Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Examples Example 1: (2 -> 4 -> 3) + (5 -> 6 -> 4) => 7 -> 0 -> 8 Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807 ...

Two Sum 4 - Input is Binary Search Tree

Problem Given a binary search tree T, where each node contains a positive integer, and an integer K, you have to find whether or not there exist two different nodes A and B such that A.value + B.value = K. Return 1 to denote that two such nodes exist. Return 0, otherwise. OR Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target. ...

Binary Search Tree BST Inorder Iterator

Problem Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST. boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false. int next() Moves the pointer to the right, then returns the number at the pointer. Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST. ...

Invert Binary Tree Problem

Problem Given the root of a binary tree, invert the tree, and return its root. OR Change a tree so that the roles of the left and right pointers are swapped at every node. Example Example 1 Given binary tree 1 / \ 2 3 / \ / \ 4 5 6 7 ...

Largest Number From Given Numbers

Problem Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. Example Example 1: Input: nums = [10,2] Output: "210" Example 2: Input: nums = [3,30,34,5,9] Output: "9534330" ...

Implement Power Function 2

Problem Implement pow(x, n) % d. In other words, given x, n and d, find (x^n % d) Note that remainders on division cannot be negative. In other words, make sure the answer you return is non negative. Examples Example 1: Input: x = 2, n = 3, d = 3 Output: 2 Explanation: 2^3 % 3 = 8 % 3 = 2. ...

Reverse Linked List 2 - between m and n

Problem Reverse a linked list from position m to n. Do it in-place and in one-pass. OR Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. Examples Example 1: --- title: Input --- graph LR A1[1] --> B2[2]:::reversed --> C3[3]:::reversed --> D4[4]:::reversed --> E5[5] classDef reversed fill:#ffcc00,stroke:#000,stroke-width:2px; ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy