Range Sum of BST

Let’s discuss a problem range sum of BST (binary search tree).

In this problem, given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].

Binary Search Tree (BST)

In binary search tree, the value of all the nodes in the left sub-tree is less than the value of the root node. Similarly, Value of all the nodes in the right sub-tree is greater than or equal to the value of the root.

For example

In the below example (image), we have to find the sum of all nodes whose value lies in the range of 7 to 15 (inclusive).

The nodes 7, 10, and 15 lie in this range and its sum is 32.

Add Two Numbers

Let’s discuss a problem add two numbers as lists and their java code.

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. We have to write a code to add these two numbers and return the sum as a linked list.

For this problem, you may assume the two numbers do not contain any leading zero, except the number 0 itself.

For example –

Linked List 1 : 2 -> 4 -> 6 -> NULL

Linked List 2 : 5 -> 6 -> 4 -> NULL

Result : 7 -> 0 -> 1 -> 1 -> NULL

Explanation :

In this example first, we added 2 and 5 the result is 7. Then, 6 and 4 the result is 10, so we put 0 and take 1 as a carry. Then, we added 6, 4, and 1 (carry) the result is 11, so we put 1 and take 1 as a carry.

Valid Palindrome II | Delete at Most One Character to Make it a Palindrome

In this tutorial, I am going to discuss a variation of palindrome questions valid palindrome II. In this problem, we can remove a character from a string to make it a palindrome.

Given a non-empty string, We may delete at most one character from a string. We have to write a code which checks whether we can make this string palindrome or not.

For example –

Example 1:

Input : “aba”
Output: true

This string is already palindrome. So we return true.

Example 2:

Input : “abca”
Output: true

This string is not a palindrome. But, if we delete either a character b or c from this string then the new string is a palindrome.