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

# Category Archives: Uncategorized

# Palindrome Number

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

# 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].

# Determine If Two Rectangles Overlap

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

# 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)).

# 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 […]

# Nuts in an Oasis

A pile of nuts is in an oasis, across a desert from a town. The pile contains ‘N’ kg of nuts, and the town is ‘D’ kilometers away from the pile. The goal of this problem is to write a program that will compute ‘X’, the maximum amount of nuts that can be transported to […]

# Studious Student Problem Analysis

You’ve been given a list of words to study and memorize. Being a diligent student of language and the arts, you’ve decided to not study them at all and instead make up pointless games based on them. One game you’ve come up with is to see how you can concatenate the words to generate the […]

# Peg Game Problem Analysis

At the arcade, you can play a simple game where a ball is dropped into the top of the game, from a position of your choosing. There are a number of pegs that the ball will bounce off of as it drops through the game. Whenever the ball hits a peg, it will bounce to […]

# Double Square Problem Analysis

A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 32 + 12. Your task in this problem is, given X, determine the number of ways in which it can be written as the sum of two squares.

# Facebook Hacker Cup Online Qualification Round Begins Now!

Facebook decided to launch Hacker Cup, a programming contest to attract the world’s best talents to their HQ. The qualification round started on Friday 4pm (US’s PST timezone) and continues for 72 hours, so go ahead and join now. Facebook’s Hacker Cup, equivalent to Google’s Code Jam. The cheapest way to attract the best talents […]

# CTRL+A, CTRL+C, CTRL+V

Imagine you have a special keyboard with the following keys: A Ctrl+A Ctrl+C Ctrl+V where CTRL+A, CTRL+C, CTRL+V each acts as one function key for “Select All”, “Copy”, and “Paste” operations respectively. If you can only press the keyboard for N times (with the above four keys), please write a program to produce maximum numbers […]

# Stack that Support Push, Pop, and GetMin in Constant Time

Design a stack that supports push, pop, and retrieving the minimum element in constant time. Can you do this?

# Finding the Minimum Window in S which Contains All Elements from T

Given a set T of characters and a string S, find the minimum window in S which will contain all the characters in T in complexity O(n).

# Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to buy one share of the stock and sell one share of the stock, design an algorithm to find the best times to buy and sell.

# Rejection Sampling

Given a function which generates a random integer in the range 1 to 7, write a function which generates a random integer in the range 1 to 10 uniformly.

# Excel Sheet Row Numbers

Given the sequence S1 = {a,b,c,d,…,x,y,z,aa,ab,ac…. } and given that this sequence corresponds (term for term) to the sequence S2 = {0,1,2,3,….}. Write code to convert an element of S2 to the corresponding element of S1.

# Problem C: Theme Park Solution (Google Code Jam Qualification Round 2010)

Read the question here from GCJ Qualification Round 2010:» Problem C: Theme Park

# Problem B: Fair Warning Solution (Google Code Jam Qualification Round 2010)

Read the question here from GCJ Qualification Round 2010:» Problem B: Fair Warning

# Google Code Jam Qualification Round 2010

Google Code Jam has begun and there is still time to compete, so register and start coding now if you have not! » Participate in Google Code Jam Now!