## Word Search Leetcode Solution

Problem Statement Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where “adjacent” cells are horizontally or vertically neighbouring. The same letter cell may not be used more than once. Example …

## Maximum Subarray Leetcode Solution

Problem Statement Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example nums = [-2,1,-3,4,-1,2,1,-5,4] 6 Explanation: [4,-1,2,1] has the largest sum = 6. nums = [-1] -1 Approach 1 (Divide and Conquer) In this approach …

## Subtract the Product and Sum of Digits of an Integer Leetcode Solution

Problem Statement In this problem, we need to find the difference between the product of digits and the sum of digits of a given positive integer. Example 1234 14 Explanation: Product = 4 * 3 * 2 * 1 = 24 and Sum = 4 + 3 + 2  + …

## Palindrome Linked List Leetcode Solution

In the problem “Palindrome Linked List”, we have to check whether a given singly integer linked list is a palindrome or not. Example List = {1 -> 2 -> 3 -> 2 -> 1} true Explanation #1: The list is palindrome as all elements from the start and back are …

## Convert Sorted Array to Binary Search Tree Leetcode Solution

Consider we are given a sorted array of integers. The goal is to build a Binary Search Tree from this array such that the tree is height-balanced. Note that a tree is said to be height-balanced if the height difference of left and right subtrees of any node in the …

## Merge Sorted Arrays Leetcode Solution

In the problem “Merge Sorted Arrays”, we are given two arrays sorted in non-descending order. The first array is not fully filled and has enough space to accommodate all elements of the second array as well. We have to merge the two arrays, such that the first array contains elements …

## Search in Rotated Sorted Array Leetcode Solution

Consider a sorted array but one index was picked and the array was rotated at that point. Now, once the array has been rotated you are required to find a particular target element and return its index. In case, the element is not present, return -1. The problem is generally …

## House Robber Leetcode Solution

Problem Statement In this problem there are houses in a street and House robber has to rob these houses. But the problem is that he can’t rob more than one house successively i.e which are adjacent to each other. Given a list of non-negative integers representing the amount of money …

## Sum of f(a[i], a[j]) over all pairs in an array of n integers

The problem statement asks to find out the Sum of f(a[i], a[j]) over all pairs in an array of n integers in such a way that 1 < = i < j < = n considering that we are provided an array of integers. Example arr[] = {1, 2, 3, …

## Given an Array of Pairs Find all Symmetric Pairs in it

Find all symmetric pairs – You are given some pairs of an array. You have to find out the symmetric pairs in it. The symmetric pair is said to be symmetric when in pairs say (a, b) and (c, d) in which ‘b’ is equal to ‘c’ and ‘a’ is …