Let's Talk Algorithms

Complex Algorithms Simplified

  • Home
  • Interview Prep
  • About
Subscribe
Frequently Asked Questions

Calculate the Hamming Distance between two Integers

Problem Statement Given two integers, calculate the hamming distance between them. Solution Explanation Hamming Distance between integers is defined as the number of indexes where the two bits differ. For example, given integers

Venkatesh Thallam
Data Structures

Doubly Linked List Implementation Java

LinkedList is a linear data structure which allows to insert and remove elements at the front and rear in constant time. LinkedLists are typically of two types, Single LinkedList Each node has a

Venkatesh Thallam
Data Structures

Introduction to Queue and Implementation using Linked List

Queue is a linear datastructure that stores elements with first in first out(FIFO) ordering. That is, the element which gets added to the queue leaves before all the elements added after it.

Venkatesh Thallam
Data Structures

Stack Implementation using Single LinkedList Java

Stack is one of the most used data structures in computer science. It is a linear data structure which supports ordering of elements in Last In First Out order(LIFO). The very typical

Venkatesh Thallam
Array

Trapping Rain Water Solution Java

Problem Statement Given an a list of n integers which are non negative and represent an elevation map of various buildings where the width of each bar/building is 1, Find out how

Venkatesh Thallam
Array

Find K Pairs with Smallest Sum Java Solution

Problem Statement Given two integer arrays, arr1 and arr2, find K pairs of elements such that (x,y) where x is the value from the first array and y is the value from

Venkatesh Thallam
Array

Find Two Numbers in an Array Which Sum Up to K

Problem Statement Given an array of integers, find out two indices such that the sum of the numbers at that indices matches K. For example, {4, 6, 8, 1, 9} and K = 15,

Venkatesh Thallam
Array

Check If a Sudoku is Valid

Problem Statement Determine if a sudoku is Valid. Solution Explanation Given a sudoku grid, we need to verify if the already filled in numbers doesn't violate the sudoku rules. The rules are very

Venkatesh Thallam
Math

Generate all Factor Combinations

Problem Statement Given a number 'n', generate all factor combinations. For example, when n=24, the result would be [[2, 3, 3], [2, 9], [3, 6]] Solution Explanation As we know, every integer

Venkatesh Thallam
Linked List

Check if a LinkedList has a cycle

Problem Statement Given a single linked list, verify if the list has a cycle. A linked list has a cycle if a node's reference points back to an earlier node in the chain.

Venkatesh Thallam
Array

Best Time to Buy and Sell Stock

Problem Statement Given an array 'stocks' in which each value at index 'i' is the stock price on day 'i', Find the maximum profit you can make by performing atmost one Buy and

Venkatesh Thallam
Leetcode Medium

Find Inorder Successor in a Binary Search Tree

Problem Statement Given a binary search tree and the value of a certain node, find the next node in the inorder sequence after the given node. Solution Explanation The important information here is

Venkatesh Thallam
Linked List

Linked List Implementation Java

Problem Statement Implement a single linked list in Java Solution Explanation Linked List is one of the heavily used data structure in computer programming. It is basically a linear collection of data elements

Venkatesh Thallam
Array

Number of Islands Leetcode

Problem Statement Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or

Venkatesh Thallam
Math

Find the Celebrity

Problem Statement Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that

Venkatesh Thallam
Array

Three Sum(3Sum) Leetcode

Problem Statement Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the

Venkatesh Thallam
Array

Meeting Rooms Leetcode

Problem Statement Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. For example, Given

Venkatesh Thallam
String

Decode Ways Leetcode

Problem Statement A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message

Venkatesh Thallam
String

Letter Combinations of a Phone Number

Problem Statement Given a digit string, return all possible letter combinations that the number could represent. Input:Digit string "23" Output: ["ad", "ae", "af", "

Venkatesh Thallam
Interview Questions

Add Binary Leetcode

Problem Statement Given two binary strings, return their sum (also a binary string). For example,a = "11", b = "1" Return "100". Solution Explanation The question is very

Venkatesh Thallam
Binary Tree

Binary Tree Vertical Order Traversal Leetcode

Problem Statement Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). Solution Explanation Given a binary tree, 35 / \ 23 27 / \ \ 14

Venkatesh Thallam
Array

Sparse Matrix Multiplication

Problem Statement Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. Solution Explanation A sparse matrix is

Venkatesh Thallam
Binary Search

First Bad Version Leetcode

Problem Statement Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad. You are given an

Venkatesh Thallam
Array

Maximum Size Subarray Sum Equals K Leetcode

Maximum Size Subarray Sum Equals K Leetcode

Venkatesh Thallam
Leetcode Easy

Reverse a LinkedList Java

Problem Statement Reverse a singly linked list. Given a single linked list, reverse it in place. Explanation Given a linked list like below, 1 -> 2 -> 3 -> 4

Venkatesh Thallam
Let's Talk Algorithms © 2018
Latest Posts Ghost

Subscribe to Let's Talk Algorithms

Stay up to date! Get all the latest & greatest posts delivered straight to your inbox