Clone a graph. Input is a Node pointer. Return the Node pointer of the cloned graph.

# Author Archives: 1337c0d3r

# Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

# Longest Palindromic Substring Part II

Given a string S, find the longest palindromic substring in S. Note: This is Part II of the article: Longest Palindromic Substring. Here, we describe an algorithm (Manacher’s algorithm) which finds the longest palindromic substring in linear time. Please read Part I for more background information.

# Longest Palindromic Substring Part I

Given a string S, find the longest palindromic substring in S.

# Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’.

# Insert into a Cyclic Sorted List

Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted list. The given node can be any single node in the list.

# Reverse Bits

Reverse bits of an unsigned integer.

# Lowest Common Ancestor of a Binary Tree Part II

Given a binary tree, find the lowest common ancestor of two given nodes in the tree. Each node contains a parent pointer which links to its parent.

# Lowest Common Ancestor of a Binary Tree Part I

Given a binary tree, find the lowest common ancestor of two given nodes in the tree.

# Lowest Common Ancestor of a Binary Search Tree (BST)

Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the BST.

# A Distance Maximizing Problem

Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j].

# Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.

# Determine If Two Rectangles Overlap

Given two axis-aligned rectangles A and B. Write a function to determine if the two rectangles overlap.

# Construct Binary Tree From Inorder and Preorder/Postorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree.

# The Painter’s Partition Problem Part II

Note: This is Part II of the article: The Painter’s Partition Problem. Please read Part I for more background information.

# The Painter’s Partition Problem Part I

You have to paint N boards of length {A0, A1, A2 … AN-1}. There are K painters available and you are also given how much time a painter takes to paint 1 unit of board. You have to get this job done as soon as possible under the constraints that any painter will only paint […]

# Median of Two Sorted Arrays

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

# Coins in a Line

There are n coins in a line. (Assume n is even). Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins. Would you rather go first or second? Does it matter? Assume that […]

# Find the k-th Smallest Element in the Union of Two Sorted Arrays

Given two sorted arrays A, B of size m and n respectively. Find the k-th smallest element in the union of A and B. You can assume that there are no duplicate elements.

# Sliding Window Maximum

A long array A[] is given to you. There is a sliding window of size w which is moving from the very left of the array to the very right. You can only see the w numbers in the window. Each time the sliding window moves rightwards by one position. Following is an example: The […]