Spiral Matrix II Leetcode Problem Statement Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: Input: 3 Output: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] Solution ExplanationThis problem is similar to Spiral Matrix Leetcode problem.

Arrays Spiral Matrix Leetcode Problem Statement Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,

Reverse String Leetcode Problem Statement Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You

Array Single Number Leetcode Problem Statement Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,1] Output: 1

golang 2D Array Initialization in Golang A two dimensional array in Go require you to explicitly allocate the space for the whole array. If you want a 2-D array with 4 rows and 5 columns of integer type, below is the sample code. arr := make([][]int, 4) for i := range

Analytics Analysis of 2018 Hacker News "Who is Hiring" Job Posts Image showing all the locations from the Hacker News Who is Hiring Job PostsIf you are an avid Hacker News user, you would know that there's a hiring comment thread during the start of every month called, Who is Hiring. Hundreds of companies from

Leetcode Leetcode Premium vs Lintcode VIP Leetcode, Lintcode, Hackerrank, Hackerearth and Interviewbit are some of the leading preparation platforms. Of all these, Leetcode is the most famous one because of its vast collection of questions and a company focussed preparation style.

Leetcode Medium Longest Palindromic Substring Java Problem Statement Given a string, Find the longest palindromic substring. Solution Explanation Understanding the question here is very simple, given a string RENTNOW, the substring NTN is a palindrome of length 3, and that would be the result. Brute Force Before we think of

Leetcode Easy Balanced Parentheses Validation - Java Problem Statement Given an string or expression which only consists of characters like (, ), [, ], {, } . Validate if the string has balanced parentheses. A string has balanced parentheses, if every open bracket has an associated closed one and they exist in the right order. Solution Explanation As

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 x = 2 and y=5, the hamming distance between them is,

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 reference to the next node. Doubly LinkedList Each node has a

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. The most typical example is a real world queue, where you

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 real world example is a stack of plates, where new plates

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 much water can be saved in between them when it rains.

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 the second array who sum is the smallest. For example, give

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, the output would be [1,4] Solution Explanation The questions is

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 simple, Each row has numbers from 1-9 and no repitions Each

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 can be formed by product or multiplication of some numbers. These

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. Example: 1 -> 2 -> 3 -> 4

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 one Sell on these stock prices. Example 1: Input: [10, 1,

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 that the tree is a binary search tree and we need

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 and is represented by a group of nodes each pointing to

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 vertically. You may assume all four edges of the grid are

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 all the other n - 1 people know him/her but

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 sum of zero. Solution Explanation Given an integer array like below,