Plus One | Add One to Number Represented as Array

In this problem, We have given a non-empty array which represents a non-negative integer. Write a code to add one to the number.

Each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1 –

Input:  [1, 3, 4]

Output: [1, 3, 5]

In this example, the array represents the number 134. When we add 1 to it, the new number is 135.

Example 2 –

Input : [1, 2, 9]

Output: [1, 3, 0]

The number is 129. When we add 1 to 129. The new number is 130.

Example 3 –

Input : [9, 9, 9]

Output: [1, 0, 0, 0]

For the number 999, when you add 1, the new number would be 1000. If you think in terms of array, the new array size would be the previous array size plus one.

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.

Add Two Numbers – II

Let’s discuss a very interesting problem add two numbers represented by linked lists.

Problem Statement

Given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and least significant digit comes last. Each of the linked list node contain a single digit.

We have to write a code to add the two numbers and return it as a linked list.

Both the numbers do not contain any leading zero, except the number 0 itself.

NOTE: Reversing a linked list is not allowed.

For Example –

List 1 : 7 -> 2 -> 4 -> 3 -> NULL

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

Result : 7 -> 8 -> 0 -> 7 -> NULL

Explanation : The first linked list is representing the number 7243 and the second linked is representing the number 564. If we add these two numbers we get 7807, which we have to return in the form of a linked list.