Algorithmic Problems and Solutions

Find the pair with the smallest difference in two unsorted arrays.Given two nonempty arrays of integers, find the pair of values (one value from each array) with the smallest (nonnegative) difference.

Find the closest element to a target value in a binary search treeGiven a nonempty binary search tree and a target value, find the value in the BST that is closest to the target.

Convert Sorted Array to Balanced Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST. A heightbalanced 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.

Given a binary tree, determine if it is heightbalancedGiven a binary tree, determine if it is heightbalanced. A heightbalanced 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.

Symmetric Binary Tree (Mirror image of itself) problemGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

Identical Binary Trees (Same Tree) problemGiven two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

Valid Parentheses problemGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid.

Merge Two Sorted Linked ListsMerge two sorted linked lists and return it as a new list. The new list should also be sorted.

Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. For example, given the string babad, bab or aba is the longest palindromic substring.

Maximum Contiguous Subarray SumGiven an integer array numbers, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Add two numbers represented using Linked ListsYou are given two nonempty linked lists representing two nonnegative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Design and implement a data structure for Least Recently Used (LRU) cacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the get(key) and put(key, value) operations.

Reverse a Singly Linked ListReverse a Singly Linked List solution in Java. To reverse a singly LinkedList, we can keep two pointers  one pointing to the currentNode and another pointing to the previous node. Now, we can iterate over the LinkedList, and for every iteration  we reverse the pointers (Point currentNode.next to prevNode), and move the two pointers to their next node in the LinkedList.

Three Number Sum Problem (Find all triplets with the given sum)Given an array of integers, find all triplets in the array that sum up to a given target value.

Two Number Sum Problem solution in JavaGiven an array of integers, return the indices of the two numbers whose sum is equal to a given target.