Letter Combinations of a Phone Number

Problem statement: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Below is the sample input and output: Input: "23" Output: ["ad", […]

Remove Nth Node from End of List

Problem description: Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Here I shall be solving with 2 different type of solution. Solution 1: Fast […]

Find the Container with Most Water explanation with diagram and solution

Problem description: Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains […]

Longest Palindromic Substring In C++

Given a string, find the longest palindromic string in that array. A palindromic string will give the same string when read reverse. Example: “aba” reverse is “aba” hence is a palindromic string. Input: ashdkabajjseiw Output: aba Please try to solve in O(n^2). There are 3 approaches, in this topic we shall discuss 2 methods 1. […]