Palindrome Number Problem

Problem Determine whether an integer is a palindrome. Follow up Do this without extra space. Definition Palindrome Definition Examples Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left. Example 2: Input: x = -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. ...

Balanced Binary Tree Problem

Problem Implement a function to check if a tree is balanced. Definition Height-balanced binary tree: is defined as a binary tree in which the depth of the two sub-trees of every node never differ by more than 1. Examples Example 1 3 / \ 9 20 / \ 15 7 ...

Binary Tree Path Sum - Maximum Sum between any nodes

Problem A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node’s values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path. ...

Binary Tree Traversal - Zigzag Level Order Traversal

Problem Given the root of a binary tree, return the zigzag level order traversal of its nodes’ values. (i.e., from left to right, then right to left for the next level and alternate between). Example Example 1 Tree Traversal Direction 3 -> / \ 9 20 <- / \ 15 7 -> ...

Buddy Strings Problem

Problem Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j]. For example, swapping at indices 0 and 2 in "abcd" results in "cbad". Examples Example 1: ...

Construct Binary Tree from Inorder and Preorder Traversal

Problem Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. Examples Example 1: 3 / \ 9 20 / \ 15 7 ...

Contains Duplicate 2 - within k distance

Problem Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k. Examples Example 1: Input nums = [1,2,3,1], k = 3 Output: true ...

Contains Duplicate 3 - within k distance and t difference

Problem Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k. OR You are given an integer array nums and two integers indexDiff and valueDiff. Find a pair of indices (i, j) such that: ...

Convert Sorted List into a height-balanced Binary search Tree

Problem Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height balanced BST: a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Examples Example 1: Input: nums = [1, 2, 3, 4, 5, 6] Output: [3,2,5,1,null,4,6] Explanation: [4,2,5,1,3,null,6] is also accepted. ...

Count of Smaller Numbers After Self Problem

Problem Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i]. Examples Example 1: Input: nums = [5,2,6,1] Output: [2,1,1,0] Explanation: To the right of 5 there are 2 smaller elements (2 and 1). To the right of 2 there is only 1 smaller element (1). To the right of 6 there is 1 smaller element (1). To the right of 1 there is 0 smaller element. ...

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